I have a problem. I want to make a label pop up when button is clicked and it works, but I want it to make it again but with a different button. I did exactly the same in the working one and I edited to different conditions for the button you know and it doesn't work. Can somebody help me please? Thanks.
private void button3_Click(object sender, EventArgs e)
{
if (FullNameBOX.Text == "")
{
ErrorMessage.Show();
timer1.Start();
}
else if(txtEmail.Text == "")
{
ErrorMessage.Show();
timer1.Start();
}
else if(txtPassword.Text == "")
{
ErrorMessage.Show();
timer1.Start();
}
else if(txtPassword2.Text == "")
{
ErrorMessage.Show();
timer1.Start();
}
}
private void timer1_Tick(object sender, EventArgs e)
{
timer1.Stop();
ErrorMessage.Hide();
}
private void button4_Click_1 (object sender, EventArgs e)
{
if (FullnameBOX_Login.Text == "")
{
ErrorMessage2.Show();
timer2.Start();
}
else if(PasswordLogin.Text == "")
{
ErrorMessage2.Show();
timer2.Start();
}
}
private void timer2_Tick(object sender, EventArgs e)
{
timer2.Stop();
ErrorMessage2.Hide();
}
Related
I have problem, which consists in aesthetic sense, correctly - There is textBox to which i apply true condition of UseSystemPasswordChar.. It's work! But i get bold points. Try to change font size - decreases textbox's field. Below is the code (although why is it here?). Can anyone help, thank you in advance)
public partial class frmRegistr : Form
{
public frmRegistr()
{
InitializeComponent();
}
int counter = 0;
int a = 0;
string b;
private void frmRegistr_Load(object sender, EventArgs e)
{
b = label1.Text;
a = b.Length;
label1.Text = "";
timer1.Start();
}
private void label1_Click(object sender, EventArgs e)
{
}
private void label2_Click(object sender, EventArgs e)
{
}
private void timer1_Tick(object sender, EventArgs e)
{
if (counter < a)
{
counter++;
label1.Text = b.Substring(0, counter);
}
else
{
timer1.Stop();
}
}
private void label4_Click(object sender, EventArgs e)
{
timer3.Start();
}
private void label4_MouseHover(object sender, EventArgs e)
{
//if this.MouseLeave
label4.BackColor = Color.FromArgb(((int)(((byte)(154)))), ((int)(((byte)(181)))), ((int)(((byte)(101)))));
}
private void timer2_Tick(object sender, EventArgs e)
{
if (Opacity == 1)
{
timer2.Stop();
}
Opacity += .2;
}
private void timer3_Tick(object sender, EventArgs e)
{
if (Opacity <= 0)
{
this.Close();
}
Opacity -= .2;
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
textBox2.UseSystemPasswordChar = true;
}
}
}
If you want to define your own password character, use property TextBox.PasswordChar. If you want this in a certain font, use Control.Font
As you only have to do this once, do this in the constructor:
public MyForm : Form
{
InitializeComponents(),
this.textBox1.PasswordChar = '_';
this.textBox11.Font = new Font(...)
};
You can also decide to do this using the visual studio designer.
You can setup this in VisualStudio designer, but this is code:
textBox1.PasswordChar = '*';
//* = password character
I designed a dashboard form that contains buttons. Some of these buttons have sub-menus. Since I'm planning to limit the access to some sub-menus, I want that every time a user clicks a restricted sub-menu, a form will appear that will prompt the user to enter the password before accessing the restricted page.
I already made a password form and programmed that when a sub-menu is clicked, the password form will appear. However, once the correct password is submitted, it will look like this:
I want that it will look like this when password is correct:
I want the overlapping form placed on the original position / panel. How to do that?
Here's the code for the dashboard:
public CFMenu()
{
InitializeComponent();
customizeDesign();
}
private void customizeDesign()
{
panelInventory.Visible = false;
panelSales.Visible = false;
}
private void hideSubMenu()
{
if(panelInventory.Visible == true)
panelInventory.Visible = false;
if(panelSales.Visible == true)
panelSales.Visible = false;
}
private void showSubMenu(Panel subMenu)
{
if(subMenu.Visible == false)
{
hideSubMenu();
subMenu.Visible = true;
}
else
subMenu.Visible = false;
}
private void CFMenu_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'casaFrancaDataSet.Sales' table. You can move, or remove it, as needed.
this.salesTableAdapter.Fill(this.casaFrancaDataSet.Sales);
timer1.Start();
label4.Text = DateTime.Now.ToLongTimeString();
label5.Text = DateTime.Now.ToLongDateString();
}
private void btnInventory_Click(object sender, EventArgs e)
{
showSubMenu(panelInventory);
}
private void btnSales_Click(object sender, EventArgs e)
{
showSubMenu(panelSales);
}
private void button1_Click(object sender, EventArgs e)
{
openPanelForm(new CFInventoryAdd());
hideSubMenu();
}
private void button2_Click(object sender, EventArgs e)
{
openPanelForm(new PasswordInventView());
hideSubMenu();
//string password = Interaction.InputBox("Enter Password: ", "Inventory View");
//if(password == "hello")
//{
// openPanelForm(new CFInventoryView());
// hideSubMenu();
//}
//else
//{
// MessageBox.Show("Incorrect Password!");
//}
}
private void button3_Click(object sender, EventArgs e)
{
openPanelForm(new CFInventoryUpdate());
hideSubMenu();
}
private void button7_Click(object sender, EventArgs e)
{
openPanelForm(new CFSalesAdd());
hideSubMenu();
}
private void button6_Click(object sender, EventArgs e)
{
openPanelForm(new CFSalesView());
hideSubMenu();
}
private void button8_Click(object sender, EventArgs e)
{
openPanelForm(new CFCalculate());
hideSubMenu();
}
private void button5_Click(object sender, EventArgs e)
{
openPanelForm(new CFSalesUpdate());
hideSubMenu();
}
private void button9_Click(object sender, EventArgs e)
{
openPanelForm(new CFReport());
hideSubMenu();
}
private void timer1_Tick(object sender, EventArgs e)
{
label4.Text = DateTime.Now.ToLongTimeString();
timer1.Start();
}
private Form activeForm = null;
private void openPanelForm(Form childForm)
{
if (activeForm != null)
activeForm.Close();
activeForm = childForm;
childForm.TopLevel = false;
childForm.FormBorderStyle = FormBorderStyle.None;
childForm.Dock = DockStyle.Fill;
panelForm.Controls.Add(childForm);
panelForm.Tag = childForm;
childForm.BringToFront();
childForm.Show();
}
Here's a sub-menu that requires a password:
private void button2_Click(object sender, EventArgs e)
{
openPanelForm(new PasswordInventView());
hideSubMenu();
}
Here's the code for the Password Prompt form:
public partial class PasswordInventView : Form
{
public PasswordInventView()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
var password = txtPassword.Text;
if (password == "1234")
{
CFInventoryView f2 = new CFInventoryView();
f2.Show();
this.Visible = false;
}
else
{
MessageBox.Show("Username or Password is incorrect!");
txtPassword.Clear();
}
}
Before making the password form, I tried using the InputDialog from VisualBasic by referencing it on my project. I liked it however I can't set the font of the input, and I wanted that my password will appear as ******** when typed. That's why I made my own password form.
public partial class PasswordInventView : Form
Change form to UserControl.
public partial class PasswordInventView : UserControl
And create user control in main form.
If this not works go create user control and copy PasswordInventView to UserControl.
Ctrl + Alt + L > Right click project > Add > New Item > Select User Control (Windows Forms) > Add. Copy chield form to user control. And create user control in main form.
Search about user control.
The code after edit is:
private void Form1_load(object sender, EventArgs e)
{
}
private void ComboBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
try
{
if (comboBox1.Text == "Present")
{
label47.Text = DateTime.Now.ToShortDateString();
label9.Text = DateTime.Now.ToShortTimeString();
}
}
catch (Exception)
{
}
}
}
}
use selected index changed event
private void ComboBox1_SelectedIndexChanged(object sender,System.EventArgs e)
{
try
{
if(ComboBox1.Text == "present")
{
label.Text = DateTime.Now.ToString(#"MM\/dd\/yyyy HH:mm");
}
}catch(Exception)
{
}
}
I am creating a To Do List using Windows Forms.
This is what I have so far.
The code for this form is as follows
namespace To_Do_List
{
public partial class To_Do_List : Form
{
public To_Do_List()
{
InitializeComponent();
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e) //this is the exit button on the toolstrip
{
Application.Exit(); //exits the program when the Exit button is clicked in dropdown menu
}
private void button4_Click(object sender, EventArgs e)//This creates the button to open the about form
{
AboutMyProgram aboutForm = new AboutMyProgram();
aboutForm.ShowDialog(); //opens about form
}
private void button3_Click(object sender, EventArgs e) //This creates the button to open the form which ammends tasks
{
AmmendItem CreateForm = new AmmendItem(this);
CreateForm.Show();
}
private void button1_Click(object sender, EventArgs e) // This creates the button to open the form which creates new tasks
{
AddItem CreateForm = new AddItem(this);
CreateForm.Show();
}
public void listView1_SelectedIndexChanged_1(object sender, EventArgs e) // This creates the table
{
}
private void button2_Click(object sender, EventArgs e) //This Allows the user to delete entries
{
if (listView1.SelectedItems != null)
{
var confirmation = MessageBox.Show(
"Are you sure you want to delete this?",
"WARNING", MessageBoxButtons.YesNo, MessageBoxIcon.Question
);
if (confirmation == DialogResult.Yes)
{
for (int i = listView1.Items.Count - 1; i >= 0; i--)
{
if (listView1.Items[i].Selected)
{
listView1.Items[i].Remove();
i--;
}
}
}
}
}
}
}
To add a task, the form looks like this
And again, the code is as follows
namespace To_Do_List
{
public partial class AddItem : Form
{
To_Do_List home;
public AddItem(To_Do_List parent)
{
InitializeComponent();
home = parent;
}
private void label1_Click(object sender, EventArgs e)
{
}
private void label1_Click_1(object sender, EventArgs e)
{
}
private void label2_Click(object sender, EventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void menuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
}
private void openListToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void sortByDateToolStripMenuItem_Click(object sender, EventArgs e)
{
}
public void dateTimePicker1_ValueChanged(object sender, EventArgs e)
{
}
public void textBox1_TextChanged(object sender, EventArgs e)//Title Box
{
}
public void /*Description of Task*/richTextBox1_TextChanged(object sender, EventArgs e)
{
}
public void /*Priority Box*/comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Close(); //causes the window to close but keeps the application running
}
private void aboutToDoListToolStripMenuItem_Click(object sender, EventArgs e)
{
AboutMyProgram aboutForm = new AboutMyProgram();
aboutForm.ShowDialog(); //opens about form displaying copyright information
}
public void button1_Click(object sender, EventArgs e) //create task button
{
ListViewItem item1 = new ListViewItem(Title.Text);
item1.SubItems.Add(Description.Text);
item1.SubItems.Add(Priority.Text);
item1.SubItems.Add(Date.Text);
string value = "";
bool isChecked = Completed.Checked;
if (isChecked)
item1.SubItems.Add(Completed.Text);
else
value = null;
home.listView1.Items.Add(item1);
this.Close();
}
private void Date_ValueChanged(object sender, EventArgs e)
{
}
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e) //Closes the window
{
this.Close();
}
}
}
The Amend form is exactly the same as the New Task form. How would I go about being able to select a record, pressing the amend button and actually changing?
I'm pretty stumped.
Also, this isn't really part of this question but I'll ask it just in case someone knows.
How would I go about being able to actually save these records so that they are there when I open the application back up again?
Thank you very much for reading, I know that I have just dumped everything but I'm really new to Windows Forms so I didn't want to accidentally miss something important out.
Edit
Am I on the right road with something like this?
public void button1_Click(object sender, EventArgs e)
{
To_Do_List editform = new To_Do_List(Title.Text);
editform.Description.Text = listView1.SelectedItems[0].SubItems[0].Text;
Still can't get it to work :/
This code for popup window.
public partial class frmToDoDetails : Form
{
public string TaskTitle { get; set; }
public string Description { get; set; }
public bool EditMode { get; set; }
public frmToDoDetails()
{
InitializeComponent();
}
private void btnSave_Click(object sender, EventArgs e)
{
TaskTitle = txtTitle.Text;
Description = txtDesc.Text;
this.DialogResult = System.Windows.Forms.DialogResult.OK;
}
private void frmToDoDetails_Load(object sender, EventArgs e)
{
if (EditMode)
{
txtTitle.Text = TaskTitle;
txtDesc.Text = Description;
}
else {
txtTitle.Text = string.Empty;
txtDesc.Text = string.Empty;
}
txtTitle.Focus();
}
}
And this for list
public partial class frmToDo : Form
{
public frmToDo()
{
InitializeComponent();
}
private void btnNew_Click(object sender, EventArgs e)
{
frmToDoDetails frm = new frmToDoDetails();
if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
string[] arr = new string[2];
ListViewItem itm;
arr[0] = frm.TaskTitle;
arr[1] = frm.Description;
itm = new ListViewItem(arr);
listView1.Items.Add(itm);
}
}
private void frmToDo_Load(object sender, EventArgs e)
{
listView1.View = View.Details;
listView1.GridLines = true;
listView1.FullRowSelect = true;
//Add column header
listView1.Columns.Add("Title", 100);
listView1.Columns.Add("Desc", 70);
}
private void listView1_DoubleClick(object sender, EventArgs e)
{
ListViewItem currentItem= listView1.SelectedItems[0];
frmToDoDetails frm = new frmToDoDetails();
frm.TaskTitle = currentItem.SubItems[0].Text;
frm.Description = currentItem.SubItems[1].Text;
frm.EditMode = true;
if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
currentItem.SubItems[0].Text=frm.TaskTitle;
currentItem.SubItems[1].Text=frm.Description;
}
}
}
I am not added your complete fields(priority, date,etc..).
I hope it will help you.
private void tabPage3_Click(object sender, EventArgs e)
{
((Control)this.tabPage3).Enabled = false;
}
private void tabPage4_Click(object sender, EventArgs e)
{
if (GloballsClass.Role == "student")
{
((Control)this.tabPage4).Visible = false;
this.tabPage4.Hide();
}
}
private void tabPage1_Click(object sender, EventArgs e)
{
if (GloballsClass.Role == "student")
{
tabPage1.Hide();
}
}
private void WelcomePage_Load(object sender, EventArgs e)
{
I've done this some time ago. The problem is that there is no property Visible and Enabled is doing not the things you would like to do.
So here is how i'm doing it:
// Put this over the constructor
private TabPage tabPage4ToShowForNotStudents = this.tabPage4;
private TabPage tabPage1ToShowForNotStudents = this.tabPage1;
Then you have to subscribe the Load-Method of your Form:
void WelcomePage_Load(object sender, EventArgs e)
{
if (GloballsClass.Role != "student")
{
yourTabControl.TabPages.Add(this.tabPage4ToShowForNotStudents);
yourTabControl.TabPages.Add(this.tabPage1ToShowForNotStudents);
}
}
Now it will add the TabPage to your TabControl if the Role is not student. If it is it will not be added.
Be sure to not have them added in the designer otherwise it will not work.
Hope this is useful :)
thanks guys.i have sorted out the problem.
private void WelcomePage_Load(object sender, EventArgs e)
{
if (GloballsClass.Role == "student")
{
tabControl1.TabPages.Remove(tabPage5);
}
else
{
tabControl1.TabPages.Remove(tabPage4);
}
}