Thursday, April 16, 2009

Could not find any resources appropriate for the specified culture or the neutral culture.

Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "XXXYYY.en-US.resources" was correctly embedded or linked into assembly "AAABBB" at compile time, or that all the satellite assemblies required are loadable and fully signed.

I wasted a lot of time to find out the reason behind this error. This was coming up when I was trying to use culture specific satellite DLL.

After search the complete web I found the following answer:

It is not because the resource manager didn't find the satellite assembly but because the embedded .resources file in the satellite assembly doesn't have a full
name. In this case, the full name is "MyLib.Resources.es-MX.resources", but
the .resources file's name is "Resources.es-MX.resources".

When you use the resgen tool to convert .resx file to common language runtime binary .resources file, you should add the namespace name of your project in the front of the converted .resources file. The following is a sample.

resgen Resources.es-MX.resx MyLib.Resources.es-MX.resources

Thus, the .resources file has a full name. Then you use AL.exe tool to bundle the .resource file into a satellite assembly and place this satellite assembly to the es-MX subdirectory of the application's bin/debug folder.

Run the application again and you should see the correct result.


Thanks to Linda Liu [MSFT] for the answer...
source : http://www.devnewsgroups.net/group/microsoft.public.dotnet.framework/topic55934.aspx


vaibhav Chugh

Wednesday, April 8, 2009

Remove flicker in listbox C#

I read over 100 articles on the web just one was able to help me and that too was ignored by others in the discussion.

Well, if you are adding less number of items to a listbox then
listbox1.beginupdate()
listbox1.add(item);
listbox1.endupdate();

should work for you just fine. There shall be no flicker.
using doublebuffered user control / form may also solve the problem. In some cases

this.SetStyle(ControlStyles.UserPaint  ControlStyles.OptimizedDoubleBuffer 
ControlStyles.AllPaintingInWmPaint ControlStyles.SupportsTransparentBackColor,
true);
may also work.

but in my case the data was coming at a very high speed and high quantity and I had to display this large amount of data in an owner drawn list box.

this.SuspendLayout();
foreach (DataItem ditem in ditems)
{
listbox1.Items.Add(ditem);
}
this.ResumeLayout();


the above code helped me in getting a pretty smooth layout.

hope it helps
Vaibhav Chugh

Thursday, March 5, 2009

CopyRight symbol in C#

This was funny to find....

2 good ways to do it

string copyright="\u00A9";

string completetext=copyright + "myCredits";

Much better way =>
press Alt and then 0 1 6 9..this will convert into the copyright symbol

n u r good to go :)

vaibhav

Wednesday, February 18, 2009

How to release IntPtr handle C#

If you are using IntPtr as handles in C# code and wish to avoid handle leaks you may use :

IntPtr handle = some handle;
Marshal.Release(handle);

Google search didn't give me correct answer instantly so I added it here :)

cherio!!
Vaibhav


Saturday, February 7, 2009

height and width of text with specific font

When you draw a string on a C# form if you want to figure out how many pixel wide and high the text will be use:

TextRenderer Class

To measure the size you may use

TextRenderer.MeasureText :

TextRenderer.MeasureText (String, Font, Size)
TextRenderer.MeasureText (IDeviceContext, String, Font, Size)
TextRenderer.MeasureText (String, Font, Size, TextFormatFlags)
TextRenderer.MeasureText (IDeviceContext, String, Font, Size, TextFormatFlags)

It returns back System.Drawing.Size which has height and width of the text you wanted.


To draw text you may use:
private void RenderText1(PaintEventArgs e)
{
TextRenderer.DrawText(e.Graphics, "Regular Text", this.Font,
new Point(10, 10), SystemColors.ControlText);
}


for more details you may visit:
http://msdn.microsoft.com/en-us/library/system.windows.forms.textrenderer(VS.80).aspx

Wednesday, February 4, 2009

Disable right click pop up on textbox in C# winform

It took me almost 3 hours to google the correct way to fix this one...

There are 2 ways of disabling right click on textbox in a C# winform.

1. create a new context menu and add it to the text box control :

TextBox textbox1 = new TextBox();
ContextMenu cm = new ContextMenu();
textbox1.controls.add(cm);

and you are done.

2. Just do
textbox1.ShortcutsEnabled = false;

second one is short and sweet....

Wednesday, January 7, 2009

Adding icon to C# application

To add an icon to the exe given out by your C# code. Do the following:

In visual studio. Select

  1. Project
  2. [Project Name] Properties
  3. Application
  4. Icon
  5. (From the Combobox select)
and apply the .ico file :)

you are all set :)

vaibhav