Click here to Skip to main content
15,887,776 members
Home / Discussions / C#
   

C#

 
GeneralRe: c#.net desktop application Deployment issue Pin
aarav1234529-Oct-14 8:29
aarav1234529-Oct-14 8:29 
GeneralRe: c#.net desktop application Deployment issue Pin
OriginalGriff29-Oct-14 9:13
mveOriginalGriff29-Oct-14 9:13 
QuestionOld famous problem. Access to Form1 from other namespace Pin
Member 1115157129-Oct-14 5:37
Member 1115157129-Oct-14 5:37 
QuestionRe: Old famous problem. Access to Form1 from other namespace Pin
Richard MacCutchan29-Oct-14 5:53
mveRichard MacCutchan29-Oct-14 5:53 
AnswerRe: Old famous problem. Access to Form1 from other namespace Pin
Dave Kreskowiak29-Oct-14 5:53
mveDave Kreskowiak29-Oct-14 5:53 
GeneralRe: Old famous problem. Access to Form1 from other namespace Pin
Member 1115157130-Oct-14 22:06
Member 1115157130-Oct-14 22:06 
GeneralRe: Old famous problem. Access to Form1 from other namespace Pin
Dave Kreskowiak31-Oct-14 7:44
mveDave Kreskowiak31-Oct-14 7:44 
AnswerRe: Old famous problem. Access to Form1 from other namespace Pin
Pete O'Hanlon29-Oct-14 5:54
mvePete O'Hanlon29-Oct-14 5:54 
Okay, if the question you are asking is why can you not access the Text property of Form1.label1, there are many problems with your code. Some are code bugs, while others are architectural. Let's start with the code bugs in your example:

1. Form1 is not public. This means that it will not be seen outside the WindowsForm namespace.
2. Even if Form1 was public, you haven't instantiated it anywhere.
3. Assuming you manage to instantiate Form1, Label1 is private, so cannot be accessed outside of Form1.
4. You have a mismatch between the case of Label1 and label1.
5. Assuming that Form1 and Label1 were public, Label1 has not been instantiated, so it cannot be used anywhere as the Windows Forms Label control (I'm guessing that's what this is), is not a static class. So, you would need to instantiate it.
6. method1 is missing the scope and parentheses.

Okay, now let's get to the big architectural issue.

You are attempting to manipulate a control on another form from method1. This is a big OO violation. You aren't just exposing the text property of the label, you're exposing all the other properties that the Label has made public. The standard way to deal with this would be to expose something inside Form1 that can be used to set this value without exposing the control that's consuming it. You might end up with something like this:
namespace WindowsForm
{
  public class Form1 : Form1
  {
    private Label Label1;
    // Do the standard WinForms initialisation....

    public string LabelText
    {
      get { return Label1.Text; }
      set { Label1.Text = value; }
    }
  }
}

namespace abc
{
  class classtest
  {
    public void method1()
    {
      Form1 form = new Form1();
      form1.LabelText = "text";
    }
  }
}
By the way, it's a good idea to rename your controls to be something more meaningful.
SuggestionRe: Old famous problem. Access to Form1 from other namespace Pin
Richard Deeming29-Oct-14 6:46
mveRichard Deeming29-Oct-14 6:46 
GeneralRe: Old famous problem. Access to Form1 from other namespace Pin
Member 1115157130-Oct-14 22:08
Member 1115157130-Oct-14 22:08 
GeneralRe: Old famous problem. Access to Form1 from other namespace Pin
Member 1115157130-Oct-14 4:19
Member 1115157130-Oct-14 4:19 
GeneralRe: Old famous problem. Access to Form1 from other namespace Pin
Pete O'Hanlon30-Oct-14 4:29
mvePete O'Hanlon30-Oct-14 4:29 
GeneralRe: Old famous problem. Access to Form1 from other namespace Pin
Member 1115157130-Oct-14 5:42
Member 1115157130-Oct-14 5:42 
GeneralRe: Old famous problem. Access to Form1 from other namespace Pin
Pete O'Hanlon30-Oct-14 5:44
mvePete O'Hanlon30-Oct-14 5:44 
GeneralRe: Old famous problem. Access to Form1 from other namespace Pin
Member 1115157130-Oct-14 6:29
Member 1115157130-Oct-14 6:29 
GeneralRe: Old famous problem. Access to Form1 from other namespace Pin
Pete O'Hanlon30-Oct-14 7:05
mvePete O'Hanlon30-Oct-14 7:05 
GeneralRe: Old famous problem. Access to Form1 from other namespace Pin
Member 1115157130-Oct-14 10:18
Member 1115157130-Oct-14 10:18 
AnswerRe: Old famous problem. Access to Form1 from other namespace Pin
OriginalGriff29-Oct-14 6:01
mveOriginalGriff29-Oct-14 6:01 
GeneralRe: Old famous problem. Access to Form1 from other namespace Pin
Member 1115157130-Oct-14 22:10
Member 1115157130-Oct-14 22:10 
QuestionBound DataGridView with unbound text box column Pin
Nigel Mackay28-Oct-14 23:54
Nigel Mackay28-Oct-14 23:54 
AnswerRe: Bound DataGridView with unbound text box column Pin
Eddy Vluggen29-Oct-14 9:51
professionalEddy Vluggen29-Oct-14 9:51 
GeneralRe: Bound DataGridView with unbound text box column Pin
Nigel Mackay29-Oct-14 15:42
Nigel Mackay29-Oct-14 15:42 
QuestionUnable to write to a parallel port Pin
Salman S7R28-Oct-14 20:12
Salman S7R28-Oct-14 20:12 
AnswerRe: Unable to write to a parallel port Pin
Garth J Lancaster28-Oct-14 20:23
professionalGarth J Lancaster28-Oct-14 20:23 
GeneralRe: Unable to write to a parallel port Pin
Salman S7R28-Oct-14 20:28
Salman S7R28-Oct-14 20:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.