• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 9198
  • Last Modified:

Textbox background image

I am working with Microsoft sample "Advanced .NET Framework (Networking) - Use Sockets", "How-To Sockets Client", which can be downloaded from here:
http://www.microsoft.com/downloads/details.aspx?familyid=08e3d5f8-033d-420b-a3b1-3074505c03f3&displaylang=en
CSharp.msi

This sample has textbox txtDisplay which is read-only and has white background. Trying to understand how this is done I found the following lines in the form code:

private void InitializeComponent() {
    System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(frmMain));

    ...
    this.txtDisplay.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("txtDisplay.BackgroundImage")));
    ...
}

I cannot reproduce this in my own project. I guess that this image is kept as embedded resource, possibly in frmMain.resx and added to exe file by compiler or linker. But how can I do the same in my project?
0
AlexFM
Asked:
AlexFM
  • 7
  • 2
  • 2
  • +2
1 Solution
 
rama_krishna580Commented:
0
 
AlexFMAuthor Commented:
Thanks, I prefer to read some explanation here. If you post link, at least this should be link to some article, and not to other message board. And, of course, in English.
0
 
ptmcompCommented:
Is the question how to embed the picture? In property window choose Build action: Embed.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
rama_krishna580Commented:
try to use this..

1.this.components = new System.ComponentModel.Container();
2.System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(frmMain));
....
....
....

this.txtDisplay.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("txtDisplay.BackgroundImage")));

have u included 1st line..
and whats the exact error you are getting..?

R.K
0
 
AlexFMAuthor Commented:
I don't get error. These are lines from the working project. I don't understand how it works. Where is bitmap? What tool can I use to do the same as done in this project? I don't see any bitmap in this project.
0
 
ptmcompCommented:
Place the bitmap in your project (like the *.cs files). Use the menu: Project - Add File. Then open the property window and change the "Build action" to embed. The bitmap will be inside the assembly and you can read it using the code lines above.
0
 
ihenryCommented:
Hi AlexFM,

It happens when the Localizable property in a window form is set to true, then project system creates resource item for each control embed to it. And the "Windows Form Designer generated code" will looks like you see in the sample project.

Hope this helps
0
 
AlexFMAuthor Commented:
Nice, I see this code now. But textbox background is still gray. How can I add this image to the form?
I don't see any image in the sample project, but textbox background is white. Maybe I am wrong and background color is set by some other way?
0
 
AlexFMAuthor Commented:
ptmcomp:
If I add bmp file to the project by the way you described, how can I load it from resource?

System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(frmMain));
this.txtDisplay.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("txtDisplay.BackgroundImage")));

Obviously, these two lines should be changed by some way. Bitmap added by such way belongs to the whole executable and not to the form, and there is no bitmap name in this code.
0
 
ihenryCommented:
Not a very good explanation, though :)

But I found this link should be able to give better idea to you,

Walkthrough: Localizing Windows Formshttp://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbwlkWalkthroughLocalizingWindowsForms.asp
0
 
AlexFMAuthor Commented:
After setting of Localizable property to True I compared two .resx files - from my project and from the sample project. They are absolutely identical. There is no background image in the sample project, but read-only textbox background is white, and in my project it is gray. Now I see that background image is not the reason, so, my question is - how to get white background in read-only textbox?
0
 
AlexFMAuthor Commented:
There is something in this project that I cannot understand. I compare textbox properties in the sample project and in my project - they are the same. I add new read-only textbox to the sample project, and it has gray color. And txtDisplay is white. How?
0
 
planoczCommented:
Hi AlexFM,

In the client side txtdisplay textbox the backcolor is set to system.window color. Which happens to be white. Its the same in the vb.net socket sample.
0
 
AlexFMAuthor Commented:
planocz:

Yes, exactly. Interesting thing that in the Properties window of any new textbox I see: BackColor : Window (white). But read-only window is grey. When I changed BackColor to some other color, and after this set it back to white, the following line was added to .cs file:

this.txtDisplay.BackColor = System.Drawing.SystemColors.Window;

Now textbox is white. Form designer behaviour is inconsistent in this case.

I returned to EE to write that I found an answer, and found your post. You are the only expert who did what I expected - opened Microsoft sample and found an answer there, so you get your points. Thanks.
0
 
planoczCommented:
glad to help.
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 7
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now