Showing posts with label C#. Show all posts
Showing posts with label C#. Show all posts

2009/05/15

Missing auto-generated Resources.Designer.cs file

If the Resources.Designer.cs file is missing and there is no Run Custom Tool option in the context menu for the Resources.cs file (or, of course, any other resources file), it probably means that the Custom Tool property of the Resources.cs file is empty:


This is what MSDN says about the Custom Tool property:
Custom tools are components that can be used to transform files from one type to another at design time. For example, a custom tool might be a dataset code generator that reads in an XML Schema (.xsd) file and generates classes in a code file that programmatically exposes its tables and columns. There is a predefined list of custom tools available in the product; this property enables you to see which custom tool is applied to a file. In rare circumstances, you might have to change the value of this property. The value of this property must be either blank or one of the built-in custom tools.
In case of Visual Studio 2008 the default tool generating the *.Designer.cs files is ResXFileCodeGenerator - type it in the property and the problem should be solved:


UPDATE:

I found an easier way to do it:

2009/01/25

furl2delicious - a tool to import bookmarks from Furl to Delicious (with tags!)

I decided to switch from Furl to Delicious. Furl is a good bookmarking service, it has a unique feature that I think is very useful - it saves a copy of every bookmarked page. But recently it's been very slow, sometimes I couldn't even log in. Moreover, I like new Delicious design and Firefox integration so much better!

So I decided to switch. But I didn't want to lose more than 500 bookmarks. I tried to use the Delicious import feature - everything went smoothly but all my tags were lost. I looked for a solution on the Internet but I didn't find a working one, so I wrote my own tool.


It imports the following data:
  • the URL,
  • the title,
  • the comments (if there were any),
  • the tags (!),
  • the date when the bookmark was created (!).
I imported my bookmarks - it took about 20 minutes; out of 515 bookmarks that left Furl 501 arrived at Delicious, I didn't investigate why 14 bookmarks were lost.

I used the Delicious.Net library and Visual C# 2005 Express Edition.

Downloads:
furl2delicious - executables
furl2delicious - source code (.NET, C#)

2008/05/01

Calling a .NET library from a VB6 application

Calling a .NET library from a VB6 application is pretty easy. There are many resources explaining how to do it (e.g. 1, 2, 3, 4). However, all of the (or at least the ones that I have read) forget to mention that, if you are using C#, there is a catch - the assemblies created in C# have a ComVisible attribute set to false by default. This simply means that they cannot be called from a VB6 application.

To change it open the AssemblyInfo.cs file, find the following line:
[assembly: ComVisible(false)]
and change it to:
[assembly: ComVisible(true)]

2007/07/27

Preventing code from being generated in InitializeComponent() method for a property

When you place controls on a form, Visual Studio generates code in the InitializeComponent() method that sets values of their properties.

If you are developing a custom control and you don't want Visual Studio to generate such code for some of its properties, you should apply the DesignerSerializationVisiblityAttribute to such properties and place DesignerSerializationVisiblity.Hidden value on them.
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public DateTime Value
{
    get { /* ... */ }
    set { /* ... */ }
}
More information about customizing the code generated by Visual Studio can be found here.

2007/04/25

Sending mail using System.Net.Mail.SmtpClient and Gmail

This code snippet:
MailMessage message = new MailMessage();
message.From = new MailAddress("somebody@gmail.com");
message.To.Add(new MailAddress("somebody-else@some.server.com"));
message.Subject = "testing...";
message.Body = "This is a test.";

SmtpClient smtp = new SmtpClient();
smtp.EnableSsl = true;
smtp.Send(message);
along with this app.config file:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.net>
    <mailSettings>
      <smtp>
        <network
          host="smtp.gmail.com"
          port="587"
          userName="somebody@gmail.com"
          password="some-password"
          defaultCredentials="false"
        />
      </smtp>
    </mailSettings>
  </system.net>
</configuration>
allows to send e-mail from .NET code using Gmail as an SMTP server.

It is crucial to remember to:
  1. set EnableSsl to true;
  2. use port 587 (not 465, clicky).

2006/12/21

A property of a custom control is not shown in the Properties pane

If you are creating a custom control and it has a property that is not shown in the Properties pane in Visual Studio IDE, ensure the property is not write-only.

Write-only properties are not shown in the Properties pane.
Read-and-write as well as read-only properties are shown in the Properties pane.

2005/09/15

How to insert multiline text when Form.AcceptButton is set?

I've just re-discovered it - I don't like re-discovering things. I have spent an hour trying to solve this problem and once I've figured out how to do it, I've realized that I had had exactly the same problem about a month ago and I had already worked it out back then.

Anyway, let's describe the problem first:
1. There is a form - myForm.
2. There is a TextBox (or RichTextBox) control on myForm - myText. There is also a Button - myButton - on the same form.
3. The AcceptButton property of myForm is set to myButton.
4. The myText.Multiline is set to true. However, pressing Enter key does not insert a newline, but activates myButton instead.

The solution is simple:
1. In myText.GotFocus (or myText.Enter) event set myForm.AcceptButton to Nothing (VB) or null (C#).
2. In myText.LostFocus (or myText.Leave) event set myForm.AcceptButton back to myButton.