How do I set the caption of one form when another form closes (C#)

I'm working on an application and I've encountered a strange issue, that I think should be simple, but isn't. What I'm trying to accomplish is set the main form's title caption to a specific value when the another form closes. Below is my most recent attempt at this.

// From the main form I have ObjectForm Objects = new ObjectForm(); Objects.GameName = this.Text; // this is a public string on the ObjectForm side // Here is what I have on the ObjectForm private void btnOK_click(object sender, EventArgs e) { MainForm Main = new MainForm(); Main.Text = this.txtGameName.Text; this.Close(); }

Any help will be gladly accepted, thanks :D

-------------Problems Reply------------

You can't just instantiate a new MainForm, you need to get a reference to the existing instance.

Have a look in the documentation at Application.OpenForms

This code you have in your button click handler

MainForm Main = new MainForm();
Main.Text = this.txtGameName.Text;

Instantiates a new MainForm and sets it's title, this is completely separate instance to the MainForm that houses your application.

Category:c# Views:0 Time:2010-07-15

Related post

  • Winforms - Click/drag anywhere in the form to move it as if clicked in the form caption 2008-08-27

    I am creating a small modal form that is used in Winforms application. It is basically a progress bar of sorts. But I would like the user to be able to click anywhere in the form and drag it to move it around on the desktop while it is still being di

  • Adding a caption to an equation in LaTeX 2008-09-29

    Well, it seems simple enough, but I can't find a way to add a caption to an equation. The caption is needed to explain the variables used in the equation, so some kind of table-like structure to keep it all aligned and pretty would be great. --------

  • Custom button captions in .NET messagebox? 2008-10-24

    Is there an easy way to display a messagebox in VB.NET with custom button captions? I came across What is an easy way to create a MessageBox with custom button text in Managed C++?, in the Stack Overflow archives, but it's for Managed C++. ----------

  • Finding if a TextBox/Label caption fits in the control 2008-11-02

    The scenario is trying to adjust font size to get a nice graphic arrangement, or trying to decide where to break a caption/subtitle. a) In XL VBA is there a way to find out whether a text on a textbox, or caption on a label, still fits the control? b

  • Windows not sizable and without caption 2008-12-12

    I want to to create a window not sizable and without caption like vista sndvol.exe --------------Solutions------------- Use WS_EX_DLGMODALFRAME style in CreateWindowEx and don't set WS_CAPTION. Read the manual about possible styles

  • Correct way to maximize form in delphi (without caption) 2008-12-19

    I have a form without caption, using on double click to maximize : Code looks like this: procedure xxxxxx; begin if Form1.WindowState=wsNormal then begin Form1.WindowState:=wsMaximized; Form1.SetBounds(0,0,screen.Width,screen.Height-getHeightOfTaskBa

  • Can I change the height of a specified window's caption bar? 2008-12-30

    I want to self-draw the caption bar of my application's window, so I decided to override OnNcPaint() methods. But I don't know how to set a different height of the caption bar. Everytime I use GetSystemMetrics(SM_CYCAPTION), it retruns the same value

  • Unicode characters in window caption 2009-01-06

    We're having trouble setting window captions using cyrillic or japanese characters. We either see question marks or random garbage, but not the text we want. We've tried using different encodings, SetWindowText(), SetWindowTextW(), SetWindowTextA(),

  • Ghost/translucent caption inside text input? 2009-01-06

    First, what does one call the ghost caption that appears in a text edit if that edit has no real text? Second, has anyone invented that particular wheel for Flex text components? Thanks --------------Solutions------------- It's called a Watermark. I'

  • How to get size and position of window caption buttons (minimise, restore, close) 2009-01-26

    Is there an API call to determine the size and position of window caption buttons? I'm trying to draw vista-style caption buttons onto an owner drawn window. I'm dealing with c/c++/mfc. Edit: Does anyone have a code example to draw the close button?

  • How to prevent a Delphi MDI application from showing the caption of the maximized child 2009-02-19

    how can I prevent a Delphi MDI application from showing the caption of the currently maximized MDI child in the caption of the MDI parent form? Thank you in advance! --------------Solutions------------- haven't had a chance to test this, but: in the

  • How do I set the GroupBox caption colour 2009-02-26

    On my system, the caption of a groupbox is always a dark blue colour, how do I change this? The answer to How do you change the color of the border on a group box? shows how I can override the drawing of the caption and border, but I don't want to ha

  • What's so bad about using button captions as variables in VB6? 2009-02-27

    I received some justified critical feedback on my last question (How to gracefully exit from the middle of a nested subroutine when user cancels?) for using the caption of a command button as a state variable. I did it because it's efficient, serving

  • Showing caption for CommandBar button with Excel VBA 2009-03-16

    I'm trying to add a button to a new CommandBar (for the Add-in tab) with Excel VBA. I can get the button into the ribbon and can get an image to show up for it if I use a FaceId, but I can't get the Caption to appear. Is there some way to do this? Do

  • What is the correct caption label for a code fragment? 2009-03-19

    I'm currently working on my Dissertation for my degree, and in writing my report, I don't know how to caption my code fragments correctly. For example... ==================================== Diagram/Image: "Figure 1 - My Diagram" Table: "Table 1 - Ta

  • Special characters in LaTeX table caption 2009-03-23

    When I include \overline{x} or other special characters in the caption text of a table, the whole caption text won't appear at all. When I put simple text without special characters, the caption works fine. How can I include special characters in the

  • Loading caption of controls from resource DLL 2009-04-15

    I am new to MFC and I need to build a multi-language application that should be able to change the language at runtime. AFAIK the common way for internationalization with MFC is to create resource-only DLLs. But there seems to be no simple way (that

  • Formatting of the caption of a chart 2009-04-28

    Does anyone of you know a way to format the caption of a chart in Crystal Reports? I have a number that stands for a specific year, this number is 4 digits long. I wnat the caption to be shown like: 2009 But the current way its shown is 2.009 EDIT: T

  • Caption outside table? 2009-04-29

    I'm trying to add a caption to a table in latex, however it throws this error "! LaTeX Error: \caption outside float." From the error I am guessing ti means that it is outside the table, but I have clearly put it inside. \begin{tabular}{|c|c|c|c|c|c|

  • Sphinx automated image numbering/captions? 2009-04-30

    Is there a way to automatically generate an image/figure caption using sphinx? I currently have rest-sphinx files I'm converting to html and (latex)pdf using sphinx. I'd like an easy way for users to reference a specific image in the resulting html/p

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.096 (s). 11 q(s)