Solved

Textbox background image

Posted on 2004-04-25
15
9,176 Views
Last Modified: 2007-12-19
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
Comment
Question by:AlexFM
  • 7
  • 2
  • 2
  • +2
15 Comments
 
LVL 23

Expert Comment

by:rama_krishna580
Comment Utility
0
 
LVL 48

Author Comment

by:AlexFM
Comment Utility
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
 
LVL 10

Expert Comment

by:ptmcomp
Comment Utility
Is the question how to embed the picture? In property window choose Build action: Embed.
0
 
LVL 23

Expert Comment

by:rama_krishna580
Comment Utility
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
 
LVL 48

Author Comment

by:AlexFM
Comment Utility
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
 
LVL 10

Expert Comment

by:ptmcomp
Comment Utility
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
 
LVL 20

Expert Comment

by:ihenry
Comment Utility
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 48

Author Comment

by:AlexFM
Comment Utility
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
 
LVL 48

Author Comment

by:AlexFM
Comment Utility
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
 
LVL 20

Expert Comment

by:ihenry
Comment Utility
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
 
LVL 48

Author Comment

by:AlexFM
Comment Utility
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
 
LVL 48

Author Comment

by:AlexFM
Comment Utility
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
 
LVL 27

Accepted Solution

by:
planocz earned 500 total points
Comment Utility
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
 
LVL 48

Author Comment

by:AlexFM
Comment Utility
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
 
LVL 27

Expert Comment

by:planocz
Comment Utility
glad to help.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now