Jump to content
  • Advertisement
Sign in to follow this  

.net Form Problems...

This topic is 4520 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a problem, I need to send a message in a text box whenever a statement is true. I activate the variable of this statement using a button. However, I can't seem to find a place to put the if statement. Form code example: http://www.developer.com/net/net/article.php/1378751 Scroll to bottom.

Share this post


Link to post
Share on other sites
Advertisement
When you say send a message in a text box, so you mean set it to something?

if(statement)
{
textBox1.Text = "Variable is true";
}

I'm not sure I understand your problem enough to help, sorry.

Share this post


Link to post
Share on other sites
Basically I need to send the same message over and over and over until a button is clicked to tell it to stop. One button activates a variable, isbutton1down = true... Now I need a loop to put an if statement in it to send the message over and over again.

Share this post


Link to post
Share on other sites
You don't understand. Using the following code:


// This is the main project file for VC++ application project
// generated using an Application Wizard.

#include "stdafx.h"

#using <mscorlib.dll>
#include <tchar.h>

#using <System.dll>
#using <System.Drawing.dll>
#using <System.Windows.Forms.dll>
#using <System.Data.dll>

using namespace System;
using namespace System::Drawing;
using namespace System::Collections;
using namespace System::ComponentModel;
using namespace System::Windows::Forms;
using namespace System::Data;

namespace cs1
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public __gc class Form1 : public System::Windows::Forms::Form
{
private:
Button* button1;
Label* label1;
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container* components;

public:
Form1()
{
//
// Required for Windows Form Designer support
//
components = NULL;
InitializeComponent();

//
// TODO: Add any constructor code after
// InitializeComponent call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected:
void Dispose( bool disposing )
{
if( disposing )
{
if (components != NULL)
{
components->Dispose();
}
}
Form::Dispose( disposing );
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private:
void InitializeComponent()
{
button1 = new Button();
label1 = new Label();
SuspendLayout();
//
// button1
//
button1->Location = Point(48, 96);
button1->Name = "button1";
button1->TabIndex = 0;
button1->Text = "Greet Me";
button1->Click += new System::EventHandler(this,
&Form1::button1_Click);
//
// label1
//
label1->Location = Point(184, 96);
label1->Name = "label1";
label1->TabIndex = 1;
//
// Form1
//
AutoScaleBaseSize = System::Drawing::Size(5, 13);
ClientSize = System::Drawing::Size(292, 273);
Controls->Add(label1);
Controls->Add(button1);
Name = "Form1";
Text = "Form1";
ResumeLayout(false);

}


private:
void button1_Click(Object* sender, System::EventArgs* e)
{
label1->Text = "Hello from C++!";
}
};
}

// This is the entry point for this application
int __stdcall WinMain()
{
Application::Run(new cs1::Form1());
return 0;
}




Follow the code structure, Form1 runs, InitializeComponent(); initializes, where would the if statement go? I've attempted it myself, after InitializeComponent(), the application displays. While application is executing I need to check if statement handlers are met and act on it.

[Edited by - Dave84311 on January 3, 2006 8:48:43 PM]

Share this post


Link to post
Share on other sites
Please use source tags.

Look up the class for w/e your using, command button or w/e it is on MSDN. That should answer your question.

Share this post


Link to post
Share on other sites
If I understand you right you want to do something like this:

user clicks a button (button1)
send a message repeatedly
don't stop until user clicks another button (button2)

to do this you'll need to create another thread in the click handler of button1. the thread proc will send the message and check a variable to see if it should continue or stop sending the message. in button 2's click handler you can set the variable that the thread proc is looking for.

hope this helps.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!