User not logged in - login - register
Home Calendar Books School Tool Photo Gallery Message Boards Users Statistics Advertise Site Info
go to bottom | |
 Message Boards » » c# questions Page [1]  
1985
All American
2175 Posts
user info
edit post

I couldn't find another thread on this.

Anyway, This seems simple enough, but I can't figure it out:

I want to change properties of form controls from another class. I can do some of it easily with gets and sets like

public string LblLabel
{
get { return lblLabel.Text; }
set { lblLabel.Text = value; }
}

in the mainForm class and placing something like this

public mainForm mainForm
{
get { return parent; }
set { parent = value; }
}

in the other class.

But that limits me to only changing the text of lblLabel, I want to do something like this:

public Label LblLabel
{
get { return lblLabel; }
set { lblLabel = value; }
}

and actually pass a Label object to the form. It doesn't throw an error when i do this, but it doesn't update my form, even when I run Refresh() or Update(), anythoughts?

9/8/2009 4:07:30 PM

afripino
All American
11347 Posts
user info
edit post

what properties are you trying to set?

[Edited on September 8, 2009 at 4:12 PM. Reason : ]

9/8/2009 4:10:14 PM

Noen
All American
31346 Posts
user info
edit post

Extend the class with an overloaded set function that can take an argumen

9/8/2009 4:12:08 PM

1985
All American
2175 Posts
user info
edit post

^ elaborate (I don't know much)?

^^ I want control of all the properties,

public Label LblLabel
{
  get { return lblLabel; }
  set { lblLabel = value as Label; }
}

should work, as far as I can tell. When I'm debugging and I step through, it changes lblLabel to the label object that I want it to be (the hover-over shows me the text and stuff that changed), but it doesn't show up on the form.

[Edited on September 8, 2009 at 5:30 PM. Reason : .]

9/8/2009 5:30:22 PM

rudeboy
All American
3049 Posts
user info
edit post

How are you calling your form control from the another class? I got it to work by using: obj.LblLabel.Text = textBox1.Text;

You may need to show how you're trying to call this method, cause it works fine for me.

9/8/2009 6:50:36 PM

1985
All American
2175 Posts
user info
edit post

^ I have

mainForm parent;

public mainForm mainForm
{
  get { return parent; }
  set { parent = value; }
}

in Class1

and in Form1 I call

Class1 PoS = new Class1();
PoS.mainForm = this;


Like I said, if I put

public string LblLabel
{
 get { return lblLabel.Text; }
 set { lblLabel.Text = value; }
}

in Form1 and set it from Class1, it works just fine, but I don't want to set lblLabel.Text, I want to set lblLabel (or, i guess, set all the properties of lblLabel at the same time to the same as some other Label)

9/8/2009 6:59:42 PM

1985
All American
2175 Posts
user info
edit post

Nevermind, I'm dumb as shit.

What I'm doing works, I just need to use

parent.label.Text = newLabel.Text

in Class1 instead of what I was doing, which was


parent.label = newLabel


^^ I think that's what you were telling me

9/8/2009 7:38:03 PM

 Message Boards » Tech Talk » c# questions Page [1]  
go to top | |
Admin Options : move topic | lock topic

© 2024 by The Wolf Web - All Rights Reserved.
The material located at this site is not endorsed, sponsored or provided by or on behalf of North Carolina State University.
Powered by CrazyWeb v2.38 - our disclaimer.