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 1 year ago.
Improve this question
I'm sure this is really simple to do but I'm struggling.
I've 6 Textboxes and I would like to copy them in Clipboard and paste them to others.
So to copy I do:
private void Btn_Copy_P1_Click(object sender, EventArgs e)
{
StringBuilder cop = new StringBuilder();
cop.AppendLine(X_Point_1_Rob.Text);
cop.AppendLine(Y_Point_1_Rob.Text);
cop.AppendLine(Z_Point_1_Rob.Text);
cop.AppendLine(Rx_Point_1_Rob.Text);
cop.AppendLine(Ry_Point_1_Rob.Text);
cop.AppendLine(Rz_Point_1_Rob.Text);
Clipboard.SetText(sb.ToString());
}
private void Btn_Paste_P2_Click(object sender, EventArgs e)
{
Clipboard.GetText()
// How it's possible to paste the 6 values from Clipboard ?
}
Do you have a working method or a solution?
Something like this, maybe?
private void Btn_Paste_P2_Click(object sender, EventArgs e)
{
string[] text = Clipboard.GetText()?.Split('\\n');
if(text == null || text.Length == 0)
return;
X_Point_1_Rob.Text = text[0];
Y_Point_1_Rob.Text = text[1];
...
Rz_Point_1_Rob.Text = text[5];
}
By the way, where do you want to paste copied snippets of text?
You can try below solution.
// Copy text to the clipboard.
private void btnCopy_Click(object sender, EventArgs e)
{
Clipboard.SetText(txtCopy.Text);
}
// Paste text from the clipboard.
private void btnPaste_Click(object sender, EventArgs e)
{
txtPaste.Text = Clipboard.GetText();
}
For more info : Copy and paste text to and from the clipboard C#
Related
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 6 years ago.
Improve this question
public partial class Form1 : Form
{
int ranNum;
Random ranNumGen;
string[] words;
const int post = 20;
public Form1()
{
words = new string[post];
ranNumGen = new Random();
words = File.ReadAllLines(#"C:\Users\User\Desktop\prog\c\c\text.txt");
}
//Start new game
private void button1_Click(object sender, EventArgs e)
{
/*here what i want is that when button1 is pressed the game would start */
}
private void label1_Click(object sender, EventArgs e)
{
/* here in label 1 what i want is random word from a text file to be displayed in a manner that it could be guessed*/
}
private void button2_Click_1(object sender, EventArgs e)
{
/* here this is a "submit" button, a word in a text box is submitted and compared to random word from the text file */
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
/* in this text box the user enters a word, and the word has to match the random word from the text file*/
}
}
}
What i want is to create a "guess the word game"
the user types in a word in a text box, and when submit button is pressed
the word submitted will be compared to the random word from a text file, if both words match the game is won. tks
What do you want to do in those handlers ?
EDIT So you want to get a random word from a file and want to display in a label ?
TO do this you can use:
var word = File.ReadAllLines(#"Location");
answer = word[new Random().Next(word.Length)];
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 7 years ago.
Improve this question
My application prints without showing the PrintDialog (and it need to do so) but I'd like to be able to set to which printer it should print so I added an appsetting in the app.config where it stores the printer name. what I want is a dialog where it shows all printer and the user should be able to choose a printer and it will save in the app.config (I could actually do it from the PrintDialog and get the chosen printer but the button says Print and I don't want to confuse the User...)
Thanks
edit
#methodMan Asked for code so I added My code
System.Windows.Forms.PrintDialog ps = new System.Windows.Forms.PrintDialog();
//set the selected printer in the dialog to the current printer
ps.PrinterSettings.PrinterName = MyApp.Properties.Settings.Default.ContinuesLabelPrinter;
var result = ps.ShowDialog();
if(result == System.Windows.Forms.DialogResult.OK)
{
MyApp.Properties.Settings.Default.ContinuesLabelPrinter = ps.PrinterSettings.PrinterName;
}
OK here is something that will work for you I think...Create a windows Form with a listbox and two buttons.
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
foreach (string printer in System.Drawing.Printing.PrinterSettings.InstalledPrinters)
{
listBox1.Items.Add(printer);
}
}
private void button1_Click(object sender, EventArgs e)
{
this.Close();
}
private void button2_Click(object sender, EventArgs e)
{
this.DialogResult = System.Windows.Forms.DialogResult.OK;
}
}
In your code do this:
Form2 form2 = new Form2();
if(form2.Show() == System.Windows.Forms.DialogResult.OK)
{
MyApp.Properties.Settings.Default.ContinuesLabelPrinter = form2.listBox1.SelectedItem.ToString();
}
form2.Dispose(); // <-- this might not be necessary
You will need to make the listBox1 public for this to work.
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
im trying to create program that changes format of imported images i dont know how to save it any help would be appreciated
--Edit; im trying save each file imported to specific folder with selected format
my code ;
private void button1_Click(object sender, EventArgs e)
{
if (dialog.ShowDialog() == DialogResult.OK)
{
foreach (String file in dialog.FileNames)
{
listView1.Items.Add(System.IO.Path.GetFileNameWithoutExtension(file));
string filee = saveFileDialog1.FileName;
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
foreach (ListViewItem item in listView1.SelectedItems)
{
listView1.Items.Remove(item);
}
}
}
}
var image = System.Drawing.Image.FromFile(inputFilename);
image.Save(outputFileName, System.Drawing.Imaging.ImageFormat.Gif);
That should do it, if I'm not mistaken. You load an image into memory from a file, then save it given whatever format you want, I chose gif here as an example.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
The program has a panel which holds a text box and the panel has two buttons on each side.
Each button acts as a 'next' (>>) and 'previous' (<<) navigation. I want to be able to navigate to the next panel by clicking '>>' this will clear the text box. Then when I click '<<' I want to go back to the previous panel with the text box containing the data previously added. However I want to do this without having to create two panels on top of each other and setting the visibility to true or false (which I am able to do). I want to achieve this by using only the one panel so the process can be done an infinite number of times. I hope this is clear to understand if you require more information please let me know.
Here is an image of my interface to clarify things:
since you have the page number, why not just create a list (or use a dictionary with the page number as a key), then in the button handler for >> and << collect the text for the current page (and put it in the list or dictionary) and replace it with the text for the previous page (from the list or dictionary).
code could look something like this:
public partial class Form1 : Form
{
Dictionary<Decimal, String> TextInfo;
public Form1()
{
InitializeComponent();
TextInfo= new Dictionary<Decimal, String>();
}
private void Form1_Load(object sender, EventArgs e)
{
numPage.Value = 1;
}
private void bnForward_Click(object sender, EventArgs e)
{
if (TextInfo.ContainsKey(numPage.Value))
{
TextInfo[numPage.Value] = textBox1.Text;
}
else
{
TextInfo.Add(numPage.Value, textBox1.Text);
}
numPage.Value++;
if (TextInfo.ContainsKey(numPage.Value))
{
textBox1.Text = TextInfo[numPage.Value];
}
else
{
textBox1.Text = "";
}
}
private void bnBack_Click(object sender, EventArgs e)
{
if (numPage.Value == 1)
return;
if (TextInfo.ContainsKey(numPage.Value))
{
TextInfo[numPage.Value] = textBox1.Text;
}
else
{
TextInfo.Add(numPage.Value, textBox1.Text);
}
numPage.Value--;
if (TextInfo.ContainsKey(numPage.Value))
{
textBox1.Text = TextInfo[numPage.Value];
}
else
{
textBox1.Text = "";
}
}
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
}
}
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 8 years ago.
Improve this question
I'm working on a windows form application and I have a button and a textbox in it.
When the button is pressed, it should make the textbox visible and hidden.
myTextbox.Visible = !myTextbox.Visible;
Did you try Google?
textBox1.Visible = false;
You can toggle the visibility by doing:
if(textBox1.Visible == true)
textBox1.Visible = false;
else
textBox1.Visible = true;
WinForm:
private void button1_Click(object sender, System.EventArgs e)
{
textBox.Visible = !textBox.Visible;
}
WPF:
private void button1_Click(object sender, RoutedEventArgs e)
{
if (textBox.Visibility != System.Windows.Visibility.Hidden)
textBox.Visibility = System.Windows.Visibility.Hidden;
else
textBox.Visibility = System.Windows.Visibility.Visible;
}
You can find an example here
private void button1_Click(object sender, System.EventArgs e)
{
/* If the CTRL key is pressed when the
* control is clicked, hide the control. */
if(Control.ModifierKeys == Keys.Control)
{
((Control)sender).Hide();
}
}
textbox.visible=true;
you should try this on buttonClick event