|
Is it possible to bind the text of a label to a variable so that if the variable changes, the displayed text on the label changes?
|
|
|
|
|
Sort of... one easy way to do this is to create a get/set for the variable and in the SET just change the text of the label as well:
<code>
private string myVariable;
public string MyVariable
{
get
{
return this.myVariable;
}
set
{
this.myVariable = value;
this.Label1.Text = value;
}
}
</code>
Now when you do something like: MyVariable = "Blah";
it will run through the "set" portion of the code and change the label as well as the internal private variable
-- modified at 14:57 Monday 10th October, 2005
|
|
|
|
|
[EDIT] Forget it, I don't think it will work the way you want.[/EDIT]
Does this work?
class MainForm : Form
{
string labelText = "Blah";
public MainForm()
{
InitializeComponent();
label1.DataBindings.Add("Text", this, "labelText");
}
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
-- modified at 21:27 Monday 10th October, 2005
|
|
|
|
|
I am working on this project in which I create dynamic dropdown lists with C# ASP.NET and I want to save each dropdownlist so that I can see what value the user selected when they click the submit button. The only thing is when a postback occurs, everything is reset. I tried saving the dropdowns in Session variables but that does not seem to work. If anyone can help, I would really appreciate that. Thanks
Sincerely,
The Major Rager
|
|
|
|
|
Typically this means you're not setting up your drop down lists in a !IsPostback block.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
This is usually (in my experience) done in the Page_Load event. Just use an if(!Page.IsPostback) block like stated above.
|
|
|
|
|
Is it possible to add an Underlined letter style shortcut to the buttons of a MessageBox dialog without wrting my own class to do it.
|
|
|
|
|
No
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I didn't think so, but my manager asked me to check.
|
|
|
|
|
Tell him you spent longer checking than it takes to write such a simple dialog, and that makes him an idiot.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
|
*grin*
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
It'd take me longer than this posting because I don't know how to do the automagic width setting based on the message string. It's an issue for complying with client provided UI standards, although I suspect we'll just br adding it to the waiver list.
|
|
|
|
|
Graphics.MeasureString
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Where/how should I make the call. I tried doing it in the set method for the relevant string, but intelisence won't show the constructor for a Graphics object, and I can't find where to find an existing one for the form.
|
|
|
|
|
Basically you need to create a graphics object for the control, use it to measure the string, and use that to resize the box, probably in the constructor, given that you probably set the string before calling showDialog
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
My problem is that even though I've got system.Drawing added to my using block, intelisence isn't showing what parameters the graphics constructor takes, and for some reason I'm not finding them among the classes methods in the help either.
|
|
|
|
|
There is no constructor, only static FromXXX methods. FromHWD is probably what you need.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Thanks. I've never done anything with the Graphics namespace before, and my experiances trying to do similar in MFC were primarily headbanging sesions.
|
|
|
|
|
|
CreateGraphics() is e mthod available from the Control class. So writing myControl.CreateGraphics whill create the appropriate Graphics object for you. Another hint: Dont forget disposing it when you don't need it anymore:
using (Graphics g = myControl.CreateGraphics()) {
}
|
|
|
|
|
I am new to C# and am doing a project using winforms.
Right now I have all individual forms (say 12 forms) for carrying out each user functionalities with proper navigation. Every thing works well. But now I want create a master form and keep all the 12 form as child forms. How do I do it.
Also even after I close the project I could still see my .exe process still running in the task manager. how do I solve this.
Thanks in advance.
|
|
|
|
|
Ann66 wrote:
But now I want create a master form and keep all the 12 form as child forms. How do I do it.
The form that gets started when you start your app should be the master form. Then it creates the child forms and uses ShowDialog to make them appear.
Ann66 wrote:
Also even after I close the project I could still see my .exe process still running in the task manager. how do I solve this.
For how long ? That just plain should not happen.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Hi All,
I'm new and trying to get cell values from a datagrid. The grid itself is read only so a double_click event or context menu selection is required on a given row to call an edit form. I can get the row selected easily enough, but can't seem to get to cell values? I thought this would be a simple datagrid1[row,cell] call. Searching the net shows lots of advanced examples using different control types in each cell and doing all sorts of stuff. I don't need to do all sorts of stuff, just a simple selection of the cell values for a given row. I'm missing something thats probably obvious because this is far from complex.
How do I execute this simple functionality?
TIA
|
|
|
|
|
never mind, got it. it was as simple as [row,col]
thanks
|
|
|
|