I have a desktop application that projects names to the screen based on the numbers received from the card reader. However, the screen is sideways, so I want the names to appear on the screen rotated 90 degrees. How can I do it?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Reader
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void label1_Click(object sender, EventArgs e)
{
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
if (textBox1.Text == "0013864285")
{
label1.Text = "Roy Randle";
textBox1.Clear();
}
if (textBox1.Text == "0016657328")
{
label1.Text = "Jake Garrett";
textBox1.Clear();
}
}
private void Form1_Load(object sender, EventArgs e)
{
textBox1.TextChanged += this.textBox1_TextChanged;
}
I made several attempts but no success.
One solution is to display the text characters vertically:
public string RotateText(string input)
{
var charArray=input.ToCharArray();
return string.Join("\n", charArray);
}
// use this function
label1.Text = RotateText("Roy Randle");
Related
I am new to C# and I want to create a windows forms application, which shows (it must be visible!) one window with some information and buttons and also it loads a page from internet (with selenium and phantom.js - though it is deprecated) every minute. I've written something like this:
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 System.IO;
using System.Diagnostics;
using OpenQA.Selenium;
using OpenQA.Selenium.PhantomJS;
namespace WindowsFormsApplication1
{
public partial class Someclass : Form
{
private void label1_Click(object sender, EventArgs e)
{
}
private void Someclass_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
// Shows some text "Hello friend"
MessageBox.Show("Hello friend!");
}
private void button2_Click(object sender, EventArgs e)
{
MessageBox.Show("Hello again", "Warning!", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
public Someclass()
{
InitializeComponent();
while (!IsDisposed)
{
MessageBox.Show("Now the page will be downloaded");
var driverService = PhantomJSDriverService.CreateDefaultService();
driverService.HideCommandPromptWindow = true;
using (var driver = new PhantomJSDriver(driverService))
{
driver.Navigate().GoToUrl("http://stackoverflow.com/");
MessageBox.Show("Here we are going to open StackOverflow");
var questions = driver.FindElements(By.ClassName("fs-display2"));
foreach (var question in questions)
{
// This will display some text from stackoverflow main page.
Console.WriteLine(question.Text);
question.Click();
MessageBox.Show("This is stackoverflow: " + question.Text);
}
MessageBox.Show("Here we go");
}
System.Threading.Thread.Sleep(60000); // delay in microseconds
}
}
}
My problem is that if I use "while", my window does not appear (but the page from internet loads correctly - every 1 minute), and if I use "if" instead of "while", my window appears well, but, of cource, the page loading goes only one time. What can solve my problem?
It's a quite simple solution: your while loop is preventing your UI from Update. You have to bring your loop in an extra Thread, or just use a backgroundworker
Yes, friends, you were right. I have put (using panel of instruments-> Background Worker):
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
this.backgroundWorker1.DoWork += new System.ComponentModel.DoWorkEventHandler(this.backgroundWorker1_DoWork);
while (!IsDisposed)
{
......................
}
System.Threading.Thread.Sleep(60000); // delay in microseconds
}
inside my public partial class someClass : Form after public Someclass()
and also added:
backgroundWorker1.RunWorkerAsync(2000);
inside my public Someclass()
So now the code looks like:
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 System.IO;
using System.Diagnostics;
using OpenQA.Selenium;
using OpenQA.Selenium.PhantomJS;
namespace WindowsFormsApplication1
{
public partial class Someclass : Form
{
private void label1_Click(object sender, EventArgs e)
{
}
private void Someclass_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
// Shows some text "Hello friend"
MessageBox.Show("Hello friend!");
}
private void button2_Click(object sender, EventArgs e)
{
MessageBox.Show("Hello again", "Warning!", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
public Someclass()
{
InitializeComponent();
backgroundWorker1.RunWorkerAsync(2000);
}
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
this.backgroundWorker1.DoWork += new System.ComponentModel.DoWorkEventHandler(this.backgroundWorker1_DoWork);
while (!IsDisposed)
{
MessageBox.Show("Now the page will be downloaded");
var driverService = PhantomJSDriverService.CreateDefaultService();
driverService.HideCommandPromptWindow = true;
using (var driver = new PhantomJSDriver(driverService))
{
driver.Navigate().GoToUrl("http://stackoverflow.com/");
MessageBox.Show("Here we are going to open StackOverflow");
var questions = driver.FindElements(By.ClassName("fs-display2"));
foreach (var question in questions)
{
// This will display some text from stackoverflow main page.
Console.WriteLine(question.Text);
question.Click();
MessageBox.Show("This is stackoverflow: " + question.Text);
}
MessageBox.Show("Here we go");
}
System.Threading.Thread.Sleep(60000); // delay in microseconds
}
}
}
and works fine.
I'm not very versed in coding, let's say this is some kind of project I started without knowing anything about coding.
I have a Button which should read the selection in the comboBox and then open a specific form.
I've tried using following the switch (comboBox1.SelectedText)
While that didn't quite work, I tried another approach:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace The_Liberion_Magnicite
{
public partial class Form1 : The_Liberion_Magnicite.Character
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void label1_Click(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
comboBox1.SelectedText.ToString();
{ if (comboBox1.SelectedText.ToString() == "Shiroichi Kazami (PTS)")
{
this.Hide();
Shiro1 CShiro1 = new Shiro1();
CShiro1.Show();
}
else if (comboBox1.SelectedText.ToString() == "Shiroichi Kazami (ATS)")
{
this.Hide();
Shiro2 CShiro2 = new Shiro2();
CShiro2.Show();
}
else if (comboBox1.SelectedText.ToString() == "Akari Hondo")
{
this.Hide();
AkariHondo CAkari = new AkariHondo();
CAkari.Show();
}
else if (comboBox1.SelectedText.ToString() == "Aboa Sekihara")
{
this.Hide();
AobaSeki CAoba = new AobaSeki();
CAoba.Show();
}
}
}
}
}
I'm in some dire need for help ;)
I have done the below code to display the list corresponding to selection in the first combo box.
But My second list is not getting loaded on the selection of items in first list :
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 WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
comboBox2.Items.Clear();
if (comboBox1.SelectedItem == "weekdays")
{
comboBox2.Items.Add("Sunday");
comboBox2.Items.Add("Monday");
comboBox2.Items.Add("Tuesday");
}
else if (comboBox1.SelectedItem == "year")
{
comboBox2.Items.Add("2012");
comboBox2.Items.Add("2013");
comboBox2.Items.Add("2014");
}
comboBox2.Show();
}
private void Form1_Load(object sender, EventArgs e)
{
comboBox1.Items.Add("weekdays");
comboBox1.Items.Add("year");
}
private void Form2_Load(object sender, EventArgs e)
{
comboBox2.Show();
}
}
}
WHat I have done wrong?
i am not sure why do you have two forms, please try following code and see if that works for you.
if (comboBox1.Text == "weekdays")
{
comboBox2.Items.Add("Sunday");
comboBox2.Items.Add("Monday");
comboBox2.Items.Add("Tuesday");
}
else if (comboBox1.Text == "year")
{
comboBox2.Items.Add("2012");
comboBox2.Items.Add("2013");
comboBox2.Items.Add("2014");
}
I am currently using WinForms Application and it seems that I have ran into a problem. I have a button that when pressed it outputs a link in a RichTextBox. However, the link is highlighted in blue but when I click it does not open in my browser. Here is the code(Note that https://something.com/ represents an actual link.):
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Project
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
richTextBox1.Text = "https://something.com/" + textBox1.Text;
}
private void richTextBox1_TextChanged(object sender, EventArgs e)
{
}
}
}
as title, i have a button that load an image in a picturebox, then when i click on it i want it to display the coordinates in two textbox, only proble...it display the coordinates when i click outside of the picturebox and not when i click in.
i already tried the solution in this site but it doesn't seems to work so far.
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 WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
protected override void OnMouseClick(MouseEventArgs e)
{
base.OnMouseClick(e);
textBox1.Text = e.X.ToString();
textBox2.Text = e.Y.ToString();
}
private void BtnBrowse_Click(object sender, EventArgs e)
{
openFileDialog1.Filter = "All jpg files (*.jpg)|*.jpg";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
pictureBox1.ImageLocation = openFileDialog1.FileName;
}
}
}
}