Click here to Skip to main content
15,897,291 members
Home / Discussions / C#
   

C#

 
QuestionEfficient way of accessing a Boolean from SQL Server Pin
Andreas_198322-Dec-08 9:35
Andreas_198322-Dec-08 9:35 
AnswerRe: Efficient way of accessing a Boolean from SQL Server Pin
Not Active22-Dec-08 10:02
mentorNot Active22-Dec-08 10:02 
AnswerRe: Efficient way of accessing a Boolean from SQL Server Pin
shea-c422-Dec-08 10:24
shea-c422-Dec-08 10:24 
GeneralRe: Efficient way of accessing a Boolean from SQL Server Pin
Andreas_198322-Dec-08 10:59
Andreas_198322-Dec-08 10:59 
GeneralRe: Efficient way of accessing a Boolean from SQL Server Pin
Mycroft Holmes22-Dec-08 15:07
professionalMycroft Holmes22-Dec-08 15:07 
GeneralRe: Efficient way of accessing a Boolean from SQL Server Pin
jchandramouli22-Dec-08 18:41
jchandramouli22-Dec-08 18:41 
GeneralRe: Efficient way of accessing a Boolean from SQL Server Pin
Mycroft Holmes22-Dec-08 18:50
professionalMycroft Holmes22-Dec-08 18:50 
QuestionVS2008 and Updating controls ? [modified] Pin
Mike Bluett22-Dec-08 8:43
Mike Bluett22-Dec-08 8:43 
PROBLEM:

The problem I am having is, given the layout of the Microsoft template for developing a Windows App, I need to know what is the best way of implementing a method to make modifications to a control on my main form (Form1).

NECESSARY BACKGROUND:

A basic Windows program comes up with a Form1.cs and a Program.cs (I have renamed Program.cs to FileOrganizer.cs).

In FileOrganizer.cs there is a Main method.

Within this Main method is "Application.Run(new Form1());".

What I want to do (within another method of the FileOrganizer class) is to update a control programmatically.

The fact that Form1 is "run" the way it is (i.e., using "Application.Run"), makes it so there is no reference to an object. Because there is no way to reference the Form1 object I don't know of a way to modify one of the controls on Form1.

If I create a global reference to Form1 and then create a "new" instance of Form1 (within Main) I receive an error ("Error 4 An object reference is required for the non-static field, method, or property 'FileOrganizer.FileOrganizer.mainForm'").


My implementation is as follows:


namespace FileOrganizer
{
    public class FileOrganizer
    {
        private Form1 mainForm;

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            mainForm = new Form1();
            Application.Run(mainForm);



I understand that this error occurs because the Main method is static although I don't understand why.

One way of making this work is by doing the following:

public class FileOrganizer
{
    private Form1 mainForm;

    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        FileOrganizer fg = new FileOrganizer();
    }

    public FileOrganizer()
    {

        mainForm = new Form1();
        mainForm.Visible = true;



But I am not sure if this is the proper way to do what I need to do (i.e., provide a way to modify a control on Form1 in another method of the FileOrganizer class).

So, given the static Main limitation, what is the proper way to implement the code so that controls on Form1 can be modified?

modified on Tuesday, December 23, 2008 4:36 PM

AnswerRe: VS2008 and Updating controls ? Pin
Not Active22-Dec-08 10:14
mentorNot Active22-Dec-08 10:14 
GeneralRe: VS2008 and Updating controls ? Pin
Mike Bluett24-Dec-08 7:07
Mike Bluett24-Dec-08 7:07 
GeneralRe: VS2008 and Updating controls ? Pin
Not Active24-Dec-08 8:16
mentorNot Active24-Dec-08 8:16 
GeneralRe: VS2008 and Updating controls ? Pin
Mike Bluett24-Dec-08 9:10
Mike Bluett24-Dec-08 9:10 
GeneralRe: VS2008 and Updating controls ? Pin
Not Active24-Dec-08 9:46
mentorNot Active24-Dec-08 9:46 
GeneralRe: VS2008 and Updating controls ? Pin
Mike Bluett24-Dec-08 9:57
Mike Bluett24-Dec-08 9:57 
AnswerRe: VS2008 and Updating controls ? Pin
Dragonfly_Lee22-Dec-08 21:19
Dragonfly_Lee22-Dec-08 21:19 
GeneralRe: VS2008 and Updating controls ? Pin
Mike Bluett23-Dec-08 10:32
Mike Bluett23-Dec-08 10:32 
GeneralRe: VS2008 and Updating controls ? Pin
Dragonfly_Lee23-Dec-08 21:10
Dragonfly_Lee23-Dec-08 21:10 
GeneralRe: VS2008 and Updating controls ? Pin
Mike Bluett24-Dec-08 7:05
Mike Bluett24-Dec-08 7:05 
GeneralRe: VS2008 and Updating controls ? Pin
Not Active24-Dec-08 8:11
mentorNot Active24-Dec-08 8:11 
AnswerRe: VS2008 and Updating controls ? Pin
Mike Bluett24-Dec-08 14:12
Mike Bluett24-Dec-08 14:12 
QuestionNeed Help in How to hook and re-route the c# function calls Pin
venkatcontact22-Dec-08 8:27
venkatcontact22-Dec-08 8:27 
AnswerRe: Need Help in How to hook and re-route the c# function calls Pin
Not Active22-Dec-08 10:10
mentorNot Active22-Dec-08 10:10 
QuestionSpecify entire app.config at runtime Pin
Chazzysb22-Dec-08 5:00
Chazzysb22-Dec-08 5:00 
AnswerRe: Specify entire app.config at runtime Pin
Not Active22-Dec-08 10:07
mentorNot Active22-Dec-08 10:07 
Question.NET 2.0 Windows Service Deployment error on Windows 2008 server. Pin
Member 357347622-Dec-08 4:22
Member 357347622-Dec-08 4:22 

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.