Click here to Skip to main content
15,889,865 members
Home / Discussions / C#
   

C#

 
GeneralRe: accessing god damn controls on other forms Pin
teknolog12326-Sep-09 2:01
teknolog12326-Sep-09 2:01 
GeneralRe: accessing god damn controls on other forms Pin
harold aptroot26-Sep-09 2:19
harold aptroot26-Sep-09 2:19 
AnswerRe: accessing god damn controls on other forms Pin
OriginalGriff26-Sep-09 2:10
mveOriginalGriff26-Sep-09 2:10 
GeneralRe: accessing god damn controls on other forms Pin
teknolog12326-Sep-09 2:20
teknolog12326-Sep-09 2:20 
GeneralRe: accessing god damn controls on other forms Pin
OriginalGriff26-Sep-09 2:23
mveOriginalGriff26-Sep-09 2:23 
AnswerRe: accessing god damn controls on other forms Pin
Alan N26-Sep-09 2:25
Alan N26-Sep-09 2:25 
GeneralRe: accessing god damn controls on other forms Pin
teknolog12326-Sep-09 2:41
teknolog12326-Sep-09 2:41 
GeneralRe: accessing god damn controls on other forms Pin
Alan N26-Sep-09 3:48
Alan N26-Sep-09 3:48 
Ok,
I'm still guessing then. The custom control, masaCubuk, is a child of MainForm and I assume that btn1.Text on the visible instance of MainForm never changes.

If that is the issue then the reason the code does not work lies in these lines:
private void button1_Click(object sender, EventArgs e)
{
  //accessing with this
  MainForm frm = new MainForm();
  frm.buttontext="sample";
} 


Here you intend to communicate with the existing MainForm but have created a new instance. What would be required to get this code fragment to work is a reference to the actual MainForm, i.e. the parent of masaCubuk. You could pass the reference as an argument to masaCubuk's constructor but doing so would introduce the tight coupling that you wish to avoid.

The accepted "loose coupling" technique is to have the main form access the custom control by subscribing to events exposed by the control.

MSDN's How To topic[^]

If you have never written an event this will seem like a lot of work but the code pattern is so standard that once learnt it is easily remembered.

Alan.
AnswerRe: accessing god damn controls on other forms Pin
DaveyM6926-Sep-09 6:51
professionalDaveyM6926-Sep-09 6:51 
GeneralRe: accessing god damn controls on other forms Pin
teknolog12326-Sep-09 9:55
teknolog12326-Sep-09 9:55 
GeneralRe: accessing god damn controls on other forms Pin
DaveyM6926-Sep-09 11:09
professionalDaveyM6926-Sep-09 11:09 
GeneralRe: accessing god damn controls on other forms Pin
teknolog12326-Sep-09 12:54
teknolog12326-Sep-09 12:54 
GeneralC# Final project Pin
Saba Minhas26-Sep-09 1:19
Saba Minhas26-Sep-09 1:19 
GeneralRe: C# Final project Pin
nagendrathecoder26-Sep-09 1:35
nagendrathecoder26-Sep-09 1:35 
GeneralRe: C# Final project Pin
Saba Minhas26-Sep-09 1:46
Saba Minhas26-Sep-09 1:46 
GeneralRe: C# Final project Pin
Abhijit Jana26-Sep-09 3:03
professionalAbhijit Jana26-Sep-09 3:03 
GeneralRe: C# Final project Pin
Saba Minhas28-Sep-09 8:31
Saba Minhas28-Sep-09 8:31 
GeneralRe: C# Final project Pin
OriginalGriff26-Sep-09 2:17
mveOriginalGriff26-Sep-09 2:17 
GeneralRe: C# Final project Pin
Saba Minhas30-Sep-09 6:46
Saba Minhas30-Sep-09 6:46 
QuestionHosting EXE Applications in a WinForm project Pin
tamir90125-Sep-09 23:55
tamir90125-Sep-09 23:55 
AnswerRe: Hosting EXE Applications in a WinForm project PinPopular
Christian Graus25-Sep-09 23:59
protectorChristian Graus25-Sep-09 23:59 
Questionbuiltin text editor in c# Pin
H.R25-Sep-09 23:40
H.R25-Sep-09 23:40 
AnswerRe: builtin text editor in c# Pin
Christian Graus25-Sep-09 23:55
protectorChristian Graus25-Sep-09 23:55 
QuestionPda and Laptop communication help Pin
hande5425-Sep-09 22:44
hande5425-Sep-09 22:44 
Question[Message Deleted] Pin
amaankhan25-Sep-09 17:21
amaankhan25-Sep-09 17:21 

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.