Solved

Textbox background image

Posted on 2004-04-25
15
9,180 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
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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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 500 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

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