?
Solved

Textbox background image

Posted on 2004-04-25
15
Medium Priority
?
9,188 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 2
  • 2
  • +2
15 Comments
 
LVL 23

Expert Comment

by:rama_krishna580
ID: 10911335
0
 
LVL 48

Author Comment

by:AlexFM
ID: 10911362
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
ID: 10911595
Is the question how to embed the picture? In property window choose Build action: Embed.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 23

Expert Comment

by:rama_krishna580
ID: 10916452
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
ID: 10916468
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
ID: 10916669
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
ID: 10917617
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
 
LVL 48

Author Comment

by:AlexFM
ID: 10917710
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
ID: 10917731
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
ID: 10917757
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
ID: 10917819
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
ID: 10917959
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 2000 total points
ID: 10917987
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
ID: 10918115
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
ID: 10918168
glad to help.
0

Featured Post

Independent Software Vendors: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

770 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