I'm trying to make certain text appear in the label when a button is clicked, but I always get the error `The name DisplayLabel does not exist in the current context. This is my Code.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Chapter_2_HW
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void sinisterButton_Click(object sender, EventArgs e)
{
MessageBox.Show("Left");
}
private void mediumButton_Click(object sender, EventArgs e)
{
}
private void dexterButton_Click(object sender, EventArgs e)
{
}
private void instructionLabel_Click(object sender, EventArgs e)
{
}
private void translateLabel_Click(object sender, EventArgs e)
{
DisplayLabel.Text = "Goodbye";
}
}
}
Related
The code is as follows:
The ServerForm Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using SimpleTCP;
namespace TCPIP
{
public partial class ServerForm : Form
{
public ServerForm()
{
InitializeComponent();
}
SimpleTcpServer server;
private void Form1_Load(object sender, EventArgs e)
{
server = new SimpleTcpServer();
server.Delimiter = 0x13; //enter
server.StringEncoder = Encoding.UTF8;
server.DataReceived += Server_DataReceived;
}
private void Server_DataReceived(object sender, SimpleTCP.Message e)
{
StatusText.Invoke((MethodInvoker)delegate ()
{
StatusText.Text = e.MessageString;
e.ReplyLine(string.Format("You said: {0}",e.MessageString));
});
// throw new NotImplementedException();
}
private void label1_Click(object sender, EventArgs e)
{
}
private void StartButton_Click(object sender, EventArgs e)
{
StatusText.Text += "Server Starting !";
System.Net.IPAddress ip = new System.Net.IPAddress(long.Parse(HostText.Text)); //error here
server.Start(ip,Convert.ToInt32(PortText.Text));
}
private void StopButton_Click(object sender, EventArgs e)
{
if(server.IsStarted)
{
server.Stop();
}
}
}
}
The Code of the ClientForm is as follows:
using SimpleTCP;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Client
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
SimpleTcpClient client;
private void ConnectButton_Click(object sender, EventArgs e)
{
ConnectButton.Enabled = false;
}
private void Form1_Load(object sender, EventArgs e)
{
client = new SimpleTcpClient();
client.StringEncoder = Encoding.UTF8;
client.DataReceived += Client_DataReceived;
}
private void Client_DataReceived(object sender, SimpleTCP.Message e)
{
StatusText.Invoke((MethodInvoker)delegate ()
{
StatusText.Text = e.MessageString;
//...
});
//throw new NotImplementedException();
}
private void SendButton_Click(object sender, EventArgs e)
{
client.WriteLineAndGetReply(TextMessage.Text, TimeSpan.FromSeconds(4));
}
}
}
The issue in the above code is that it is 'build'ing correctly and even when I am debug it with the new instance, the code is running fine, but will I debug, as soon as I press the "start" button in the Server form it shows the error in line :
System.Net.IPAddress ip = new System.Net.IPAddress(long.Parse(HostText.Text));
The error is: System.FormatException: 'Input string was not in a correct format.'
Please refer the Screenshot for details and suggest a potential fix to the issue.Image of Screenshot of Error inLine
Clearly HostText.Text is returning a value that can't be parsed into a long.
This exception is coming from long.Parse, which is really a language shortcut for Int64.Parse, whose documentation states that it will throw this exception if the input string is not formatted correctly.
hi i want to make a program that presses ctrl + v every 130 secs but it didnt worked for games (it worked for google, notepad etc.) i tried this code down below before
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace TradeChatBot
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void start_Click(object sender, EventArgs e)
{
timer1.Start();
}
private void stop_Click(object sender, EventArgs e)
{
timer1.Stop();
}
private void timer1_Tick(object sender, EventArgs e)
{
SendKeys.Send("^{v}");
SendKeys.Send("{ENTER}");
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
}
}
You can look into Clipboard class. https://msdn.microsoft.com/en-Us/library/system.windows.forms.clipboard(v=vs.110).aspx
private void Form1_Load(object sender, EventArgs e)
{
textBox1.Text= "SendKeys.Send(^{v}); ";
Clipboard.SetText(textBox1.Text);
}
private void button1_Click(object sender, EventArgs e)
{
textBox2.Focus();
SendKeys.Send("^{v}");
SendKeys.Send("{ENTER}");
}
i am new to .net i am having trouble playing videos automatically. I would be showing different textboxes here but i want the video to autplay without any buttons
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WMPLib;
namespace ThinkQDisplay
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void axWindowsMediaPlayer1_Enter(object sender, EventArgs e)
{
AxWindowsMediaPlayer1.URL = "C:\Users\Ramrod\Documents\Visual Studio 2012\Projects\ThinkQDisplay\ThinkQDisplay\sample.avi";
}
}
}
It keeps telling it is an unrecognized escape sequence. Also I would like to have a separate form (form2). Where I can choose what to play here on form 1. Is it also possible to have it looped?
private void axWindowsMediaPlayer1_Enter(object sender, EventArgs e)
{
axWindowsMediaPlayer1.URL = #"C:\Users\Ramrod\Documents\Visual Studio 2012\Projects\ThinkQDisplay\ThinkQDisplay\sampler.avi";
}
private void Form1_Load(object sender, EventArgs e)
{
axWindowsMediaPlayer1.settings.autoStart = true;
}
}
}
I am developing this project "Profiling System" using MetroFramework and I've got this problem. If I click the next button I want my system to show the other panels where it has MetroTextboxes, MetroComboboxes, MetroCheckboxes and other tools of MetroFramework, But the panels does not appear.
I also want to try the UserControl just to slide it on the form but I don't know how. Please help.
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MetroFramework.Forms;
namespace TEST.cs
{
public partial class Form1 : MetroForm
{
List<Panel> listPanel = new List<Panel>();
int index;
public Form1()
{
InitializeComponent();
}
private void btnBack_Click(object sender, EventArgs e)
{
if (index > 0)
listPanel[--index].BringToFront();
}
private void btnNext_Click(object sender, EventArgs e)
{
if (index < listPanel.Count - 1)
listPanel[++index].BringToFront();
}
private void Form1_Load(object sender, EventArgs e)
{
listPanel.Add(metroPanel1);
listPanel.Add(metroPanel2);
listPanel.Add(metroPanel3);
listPanel[index].BringToFront();
}
}
}
I have an int named "mode". I want to make every function be able to access it.
Here is my code.
namespace WindowsFormsApplication1
{
public partial class Form5 : Form
{
public Form5()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int wow = mode - 1;
}
private void Form5_Load(object sender, EventArgs e)
{
int mode = 4;
}
}
}
Just make it a property of the class.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form5 : Form
{
public int mode {get; set;}
public Form5()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int wow = mode - 1;
}
private void Form5_Load(object sender, EventArgs e)
{
mode = 4;
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form5 : Form
{
public int mode;
public Form5()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int wow = mode - 1;
}
private void Form5_Load(object sender, EventArgs e)
{
mode = 4;
}
}
}
However, I'd be surprised if there wasn't a SO page about this. Also I'd recommend looking at MSDN and other programming c#.net resources.