Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
private void calcu(double a,int x)
{
a=Convert.ToDouble(textBox1.Text);
textBox1.Clear();
}
private void button26_Click(object sender, EventArgs e)
{
calcu(a,1);
}
Are you trying to assign the variable a from the button26_Click method in the calcu method?
If so, you need to change your code a bit:
private void calcu(out double a, int x)
{
a = Convert.ToDouble(textBox1.Text);
textBox1.Clear();
}
private void button26_Click(object sender, EventArgs e)
{
double a;
calcu(out a, 1);
// Do something with `a`
}
Better yet, why not make it a function?
private double calcu(int x)
{
var a = Convert.ToDouble(textBox1.Text);
textBox1.Clear();
return a;
}
private void button26_Click(object sender, EventArgs e)
{
double a = calcu(1);
// Do something with `a`
}
private void calcu(double a,int x)
{
a=Convert.ToDouble(textBox1.Text);
textBox1.Text = "";
}
private void button26_Click(object sender, EventArgs e)
{
calcu(a,1);
}
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I've been strugling with this error for a while now.
I'm trying to implement a log in to an ATM system and I'm trying to connect it to a database as well. But when I try to run it, shows up 144 errors that are all the same:
'MyForm2': is not a member of 'jiji'
'MyForm2': undeclared identifier
Syntax error: missing ';' before identifier 'f2'
'f2':undeclared identifier
I honestly don't know why is this happening. I've tried to include MyForm2.h in the main code but nothing changes.
Here I leve the piece of code that is nearly the same for all my 7 forms ( except the 2nd that is the one that is giving the error I think)
MyForm.h:
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
try {
String^ User = textBox1->Text;
String^ Pwd = textBox2->Text;
int AN = Int32::Parse(textBox3->Text);
String^ constr = "Server=127.0.0.1;Uid=root;Pwd=;Database=visualcppdb";
MySqlConnection^ con = gcnew MySqlConnection(constr);
MySqlDataAdapter^ da = gcnew MySqlDataAdapter("Select AccountNum from Userinfo WHERE AccountNum = '" + AN + "'", con);
DataTable^ dt = gcnew DataTable();
da->Fill(dt);
if (dt->Rows->Count >= 1) {
MySqlCommand^ cmd = gcnew MySqlCommand("insert into Db values (" + AN + ") ", con);
con->Open();
MySqlDataReader^ dr = cmd->ExecuteReader();
con->Close();
try {
this->Hide();
jiji::MyForm2 f2;
f2.ShowDialog();
this->Show();
}
finally {
this->Close();
}
}
else {
MessageBox::Show("User does not exist, try again");
}
}
catch (Exception^ e) {
MessageBox::Show(e->Message);
}
}
By the way AN is the Account number.
The MyForm2.h code is the same over and over again except for the ending.
MyForm2.h:
//Extract money
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
try {
this->Hide();
jiji::MyForm3 f3;
f3.ShowDialog();
this->Show();
}
finally {
this->Close();
}
}
//Insert Money
private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {
try {
this->Hide();
jiji::MyForm4 f4;
f4.ShowDialog();
this->Show();
}
finally {
this->Close();
}
}
//Transfer
private: System::Void button3_Click(System::Object^ sender, System::EventArgs^ e) {
try {
this->Hide();
jiji::MyForm5 f5;
f5.ShowDialog();
this->Show();
}
finally {
this->Close();
}
}
//Check Amount
private: System::Void button4_Click(System::Object^ sender, System::EventArgs^ e) {
try {
this->Hide();
jiji::MyForm6 f6;
f6.ShowDialog();
this->Show();
}
finally {
this->Close();
}
}
//Reload phone
private: System::Void button5_Click(System::Object^ sender, System::EventArgs^ e) {
try {
this->Hide();
jiji::MyForm7 f7;
f7.ShowDialog();
this->Show();
}
finally {
this->Close();
}
}
//Exit
private: System::Void button6_Click(System::Object^ sender, System::EventArgs^ e) {
try {
String^ constr = "Server=127.0.0.1;Uid=root;Pwd=;Database=visualcppdb";
MySqlConnection^ con = gcnew MySqlConnection(constr);
MySqlCommand^ cmd = gcnew MySqlCommand("TRUNCATE Db ", con);
con->Open();
MySqlDataReader^ dr = cmd->ExecuteReader();
con->Close();
}
catch (Exception^ e) {
MessageBox::Show(e->Message);
}
finally {
this->Close();
}
}
Perhaps you aren't including MyForm2.h in a context MyForm.h can access?
Maybe look into how to declare a namespace and how to include headers, e.g. Creating a C++ namespace in header and source (cpp)
What happens if you inline the MyForm2 class definition into MyForm so you guarantee it is accessible?
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I would like to set values to text box, depending on values of text boxes... any idea how to do that in windows form c#? For example i have two text boxes having values and how to fill the product of the value of those text boxes in the another text box automatically? Kindly help me.
I think what you want is Control.Leave event or Control.KeyPress or you may also use Control.TextChanged as suggested by #LevZ...
Here is some code for Control.Leave Event:
TextBoxFirstNumber.Leave += TextBoxFirstNumber_Leave;
TextBoxSecondNumber.Leave += TextBoxSecondNumber_Leave;
void TextBoxFirstNumber_Leave(object sender, EventArgs e)
{
if (TextBoxFirstNumber.Text != "" && TextBoxSecondNumber.Text != "")
{
TextBoxAnswer.Text = int.Parse(TextBoxFirstNumber.Text) * int.Parse(TextBoxSecondNumber.Text);
}
}
void TextBoxSecondNumber_Leave(object sender, KeyPressEventArgs e)
{
if (TextBoxFirstNumber.Text != "" && TextBoxSecondNumber.Text != "")
{
TextBoxAnswer.Text = int.Parse(TextBoxFirstNumber.Text) * int.Parse(TextBoxSecondNumber.Text);
}
}
This will fill the TextBoxAnswer when the user puts his values in both of the TextBoxes and leaves it...
Here is some code for Control.KeyPress Event:
TextBoxFirstNumber.KeyPress += TextBoxFirstNumber_KeyPress;
TextBoxSecondNumber.KeyPress += TextBoxSecondNumber_KeyPress;
void TextBoxFirstNumber_KeyPress(object sender, EventArgs e)
{
if (e.KeyChar == (char)Keys.Enter)
{
if (TextBoxFirstNumber.Text != "" && TextBoxSecondNumber.Text != "")
{
TextBoxAnswer.Text = int.Parse(TextBoxFirstNumber.Text) * int.Parse(TextBoxSecondNumber.Text);
}
}
}
void TextBoxSecondNumber_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.Enter)
{
if (TextBoxFirstNumber.Text != "" && TextBoxSecondNumber.Text != "")
{
TextBoxAnswer.Text = int.Parse(TextBoxFirstNumber.Text) * int.Parse(TextBoxSecondNumber.Text);
}
}
}
Now the user enters numbers in both TextBoxes and presses enter on any of them TextBoxAnswer will show product...
Here is some code for Control.TextChanged Event:
TextBoxFirstNumber.TextChanged += TextBoxFirstNumber_TextChanged;
TextBoxSecondNumber.TextChanged += TextBoxSecondNumber_TextChanged;
void TextBoxFirstNumber_TextChanged(object sender, EventArgs e)
{
if (TextBoxFirstNumber.Text != "" && TextBoxSecondNumber.Text != "")
{
TextBoxAnswer.Text = int.Parse(TextBoxFirstNumber.Text) * int.Parse(TextBoxSecondNumber.Text);
}
}
void TextBoxSecondNumber_TextChanged(object sender, KeyPressEventArgs e)
{
if (TextBoxFirstNumber.Text != "" && TextBoxSecondNumber.Text != "")
{
TextBoxAnswer.Text = int.Parse(TextBoxFirstNumber.Text) * int.Parse(TextBoxSecondNumber.Text);
}
}
Now as the user will enter the numbers for event it will trigger TextChanged event and TextBoxAnswer will show output.
You may also read this Official Documentation for Control Events and use the ones that suits your needs the most.
If I understand you right, you want to update one textbox according to changes in another textbox. For this goal use TextChanged event handler
private void textBox1_TextChanged(object sender, EventArgs e)
{
textBox2.Text = ((TextBox)sender).Text;
}
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
Iam a noobi
i have this problem , i need to make a timer for my program ,which starts when the user clicks a specific button. and then to output the countdown in to a label
Thanks in advance
The DispatcherTimer is located in the System.Windows.Threading Namespace.
Something like this should work:
public partial class MainWindow : Window
{
int count = 0;
System.Windows.Threading.DispatcherTimer tmr = new System.Windows.Threading.DispatcherTimer();
public MainWindow()
{
InitializeComponent();
tmr.Interval = new TimeSpan(0, 0, 2);
tmr.Tick += new EventHandler(tmr_Tick);
}
private void button1_Click(object sender, RoutedEventArgs e)
{
tmr.Start();
}
void tmr_Tick(object sender, EventArgs e)
{
label1.Content = count += 1;
}
private void button2_Click(object sender, RoutedEventArgs e)
{
tmr.Stop();
}
}
This was pulled from production so I'm sure it works:
...
_Timer = new DispatcherTimer();
_Timer.Interval = TimeSpan.FromMilliseconds(125);
_Timer.Tick += new EventHandler(_Timer_Tick);
_Timer.IsEnabled = true;
_Timer.Start();
...
void _Timer_Tick(object sender, EventArgs e)
{
try {
...Do your thing here
} catch (Exception x){
Debug.WriteLine("Error: "+x);
}
}
I have a quick question: I need to switch between the two camera on a tablet. Front and Back. By default, the Front camera is always used by Emgu CV.
Thanks.
Ok. There is a different constructor. I was building upon the 7 line demo for Emgu CV.
Using the correct overloaded constructor, this is what did the trick for me:
private Capture _capture;
private void InitCapture(Int32 _camIndex) {
try {
if (_capture != null) {
Application.Idle -= ProcessFrame;
}
_capture = new Capture(_camIndex);
Application.Idle += ProcessFrame;
}
catch (NullReferenceException excpt) {
XtraMessageBox.Show(excpt.Message);
}
}
private void ProcessFrame(object sender, EventArgs arg) {
Image<Bgr, Byte> frame = _capture.QueryFrame();
ImageBoxCapture.Image = frame;
}
private void CharmsBarBase_ButtonTop01Click(object sender, EventArgs e) {
InitCapture(0);
}
private void CharmsBarBase_ButtonTop02Click(object sender, EventArgs e) {
InitCapture(1);
}
Regards.
I have a MediaElement, but how can I call a function when the property "position" of MediaElement changes?
Position is not a DependencyProperty.
You can use a DispatchTimer. This article provides some good insight on how to get this working. MediaElement and More with WPF.
Here is some sample code that I took from a project I'm working on. It shows the position of the video using a slider control and allows the user to change the position.
I'm a bit of a newbie too, so it is possible that some of it is wrong (feel free to comment on problems in the comments section :).
private DispatcherTimer mTimer;
private bool mIsDragging = false;
private bool mTick = false;
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
medPlayer.Play();
medPlayer.Stop();
mTimer = new DispatcherTimer();
mTimer.Interval = TimeSpan.FromMilliseconds(100);
mTimer.Tick += new EventHandler(mTimer_Tick);
mTimer.Start();
}
void mTimer_Tick(object sender, EventArgs e)
{
if (!mIsDragging)
{
try
{
mTick = true;
sldPosition.Value = medPlayer.Position.TotalMilliseconds;
}
finally
{
mTick = false;
}
}
}
private void sldPosition_DragStarted(object sender, System.Windows.Controls.Primitives.DragStartedEventArgs e)
{
mIsDragging = true;
medPlayer.Pause();
}
private void sldPosition_DragCompleted(object sender, System.Windows.Controls.Primitives.DragCompletedEventArgs e)
{
mIsDragging = false;
if (chkPlay.IsChecked.Value)
medPlayer.Play();
}
private void sldPosition_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
var pos = TimeSpan.FromMilliseconds(e.NewValue);
lblPosition.Content = string.Format("{0:00}:{1:00}", pos.Minutes, pos.Seconds);
if (!mTick)
{
medPlayer.Position = TimeSpan.FromMilliseconds(sldPosition.Value);
if (medPlayer.Position == medPlayer.NaturalDuration.TimeSpan)
{
chkPlay.IsChecked = false;
medPlayer.Stop();
}
}
}