Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
I have a button on my form, but I am unable to access it from my code. My code (from Program.cs):
Form1.button1.Text = "Button text"
I cannot access it due to it's protection level. What shall I do to change this field protection level or something?
On the properties window you can change the privacy of the components. You need to change the button privacy to public.
--EDIT
What fildor wrote is a better aproach
Changing the modifier of an object is a bad idea.
Better would be to create a public property on Form1, for example Button1Text and call that in stead of accesing a private object.
public string Button1Text
{
get { return Button1.Text; }
set {Button1.Text = value; }
}
then call it like this
form1.Button1Text = "I am a button"
Make sure that form1 is the created instance for your form, not the class name !
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
For Xamarin Forms:
I am looking to use checkboxes to enable the next set in a series. I have used x:name to set the names of the checkboxes (Fiore, Leichtenauer and Guards). My goal is to set a if statement to change the IsEnabled to false/true in the code behind when the first checkbox is checked. I seem to be getting an error for the IsEnabled, what should I be using instead? Thank you in advance.
private void CheckBox_CheckedChanged(object sender, CheckedChangedEventArgs e)
{
if (Fiore.IsChecked)
{
Leichtenauer = IsEnabled(false),
Guards = IsEnabled(true)
}
}
IsEnabled is a property of the control, so you would set it like
if (Fiore.IsChecked)
{
Leichtenauer.IsEnabled = false;
Guards.IsEnabled = true;
}
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I am working on winforms using c# where I have mutliple forms and one class. I want to use the same object of that class in all forms. How can I pass the objects from one class to another.
like in form2, I made an object user1 and then i wanna use the same user1 in form3. so for this I write a code which I have read on stake overflow but its not working.
private void loginbutton_Click(object sender, EventArgs e)
{
user1.login(textname.Text, textpassword.Text);
if (user1.success==true)
{
Form f3 = new Form3();
f3.SameUser = user2;
f3.Show();
this.Hide();
}
and then on form3 I wrote:
public partial class Form3 : Form
{
public User SameUser { get; set; }
// other function of form
}
It is giving me this error:
Inconsistent accessibility: property type 'User' is less accessible than property 'Form3.SameUser'
The problem has nothing to do with your forms. As the error states, the type User is less accessible (in this case "not public") than the form's SameUser property.
So consuming code can see the SameUser property, but might not be able to see what a User even is.
If you want that property to be public then the User class must also be public.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
I want to add a link and image to a gridview when certain conditions are met.
I think that it can be done using the below code, but I get confused about where the " go and I know that some of them need to be \" but I'm not sure where. At the moment this won't compile, please could someone help me with this?
I've also investigated using an image button but that way seems more complex in my case, as the button should only appear in rows that fit the conditions. I'm open to using that method instead if you think that it's better.
if(line.SuperSessionIndicator == "1" || line.ErrorType =="S" )
{
lbl3.Text = "<aref=\"https://stackoverflow.com/questions/7167839/aspimage-with-link \">"<img url='Images/Prop.png\'/>\"\"<a/>";
}
You need to use following code to get it right.
lbl3.Text = "<a href=\"https://stackoverflow.com/questions/7167839/aspimage-with-link\"><img src='Images/Prop.png\'/><a/>";
The resulting markup from above C# code would be as below which looks correct.
<a href="https://stackoverflow.com/questions/7167839/aspimage-with-link"><img src='Images/Prop.png'/><a/>
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
Every time I'd put in static it would keep replacing it with ContextStaticAttribute.
I need 10 rep to post images, but here's the link: http://i.imgur.com/jBOOF3s.png)
I also do not want to have to press the right arrow to put in a local variable!
I just figured out how you did this by typing static inside a method.
Variables in a method cannot be static, only class level elements can.
Simply declare those variables inside the class, not a method.
Example:
namespace ConsoleApplication2
{
class Program
{
static string username; // Correct
private static void Main()
{
static // Incorrect
}
}
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
if (Operators.CompareString(this.ParentForm.ActiveControl.Name, this.Name, false) == 0)
{
base.Focus();
}
From What I have experience in VB6,the above code doesn't work because they are never equal if the users didn't change to the same name.
From Example, the UserControl Name is ucCalendar, When I drag to my From, the name will automatically change to ucCalendar1,even though I can change to ucCalendar but usually we won't do that.
I think the coder want to compare whether the UserControl is the only control or ActiveControl on the Form so that he can force to focus it.
I don't know this C# works or not. Please tell me.
There is nothing in the WinForms code saying that two controls can not have the same name. The reason you think that is that you're looking at it from the designer perspective, when you use the designer it won't let you have two controls with the same name just because it uses there as field names for them in the code, and as you probably know there can not be two fields / properties / variables with the same name in the same scope. As a matter of fact there is no need for the Control's Name property to be anything.