Solved

Textbox background image

Posted on 2004-04-25
15
9,178 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Windows Service to Receive TCP Packets 4 117
Different Delete Messages 7 37
DateTimepicker 4 33
Two different visual studio versions 3 21
Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

930 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

18 Experts available now in Live!

Get 1:1 Help Now