1 / 57

DateTimePicker & MonthCalendar

DateTimePicker & MonthCalendar. dateTimePicker1. Format = DateTimePickerFormat. Custom ; dateTimePicker1. CustomFormat = " MMMM dd , yyyy - dddd " ; Next Slide to see list Custom Format. ListBox. private void frmListBox_Load ( object sender, EventArgs e)

mave
Download Presentation

DateTimePicker & MonthCalendar

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. DateTimePicker & MonthCalendar

  2. dateTimePicker1.Format = DateTimePickerFormat.Custom; dateTimePicker1.CustomFormat = "MMMM dd, yyyy - dddd"; Next Slide to see list Custom Format

  3. ListBox privatevoid frmListBox_Load(objectsender, EventArgs e) {listBox1.Items.Clear(); for(int i = 0; i < 10; i++) listBox1.Items.Add("Item " + i); } privatevoidlistBox1_SelectedIndexChanged (object sender, EventArgs e) { lblMessage.Text= listBox1.Text +" was clicked!"; }

  4. And We can use AddRangemethod to add data: privatevoidfrmListBox_Load(object sender, EventArgs e) { string[] strArr = newstring[] { "Tèo","Tí","Bin","Bo"}; listBox1.Items.AddRange(strArr); }

  5. publicclassCStudent { privatestringm_strID; privatestringm_strName; publicCStudent(stringstrID, stringstrName) { this.m_strID = strID; this.m_strName = strName; } publicstring ID { get{ returnthis.m_strID; } set{ this.m_strID = value; } } publicstring Name { get{ returnthis.m_strName; } set{ this.m_strName = value; } } }

  6. usingSystem.Collections; Also We can use DataSource to display data ArrayListarr = newArrayList(); for(inti=0;i<10;i++) {arr.Add(newCStudent("ID_"+i,"Name "+i)); } listBox1.DataSource = arr; listBox1.ValueMember = "ID"; listBox1.DisplayMember = "Name";

  7. To get object from Listbox, We could use coding below: if(listBox1.SelectedItem != null) { CStudentsvTeo= (CStudent) listBox1.SelectedItem; lblMessage.Text= aStudent.Name + " Was selected"; }

  8. CheckedListBox btnAdd btnAddAll chklbLeft chklbRight btnRemove btnRemoveAll

  9. Use Items to add data privatevoidfrmCheckListBox_Load (object sender, EventArgs e) { chklbLeft.Items.Add("Tèo"); chklbLeft.Items.Add("Tí"); chklbLeft.Items.Add("Bin"); chklbLeft.Items.Add("Bo"); } Or we could use AddRange chklbLeft.Items.AddRange(new string[] { "Tèo","Tí","Bin","Bo"});

  10. How to process Items Checked??? Case 1: CheckedListBox.CheckedIndexCollectionindexCollection = chklbLeft.CheckedIndices; stringstrChecked = ""; foreach(intiinindexCollection) { strChecked+= i + ";"; } MessageBox.Show(strChecked);

  11. How to process Items Checked??? Case 2: CheckedListBox.CheckedItemCollectionitems = chklbLeft.CheckedItems; stringstrChecked= ""; foreach(string s in items) { strChecked+= s + ";"; } MessageBox.Show(strChecked);

  12. How to process Items Checked??? Case 3: stringstrChecked= ""; for(int i = 0; i < chklbLeft.Items.Count; i++){ if(chklbLeft.GetItemChecked(i)) { //Process Item checked here } }

  13. Go back ChecklistBox Example: privatevoidbtnAdd_Click (object sender, EventArgs e) { foreach(inti inchklbLeft.CheckedIndices) { chklbRight.Items.Add(chklbLeft.Items[i]); } foreach(string s inchklbRight.Items) {chklbLeft.Items.Remove(s);} }

  14. privatevoidbtnAddAll_Click (object sender, EventArgs e) { chklbRight.Items.AddRange (chklbLeft.Items); chklbLeft.Items.Clear(); }

  15. privatevoidbtnRemove_Click (object sender, EventArgs e) { foreach(string s inchklbRight.CheckedItems) chklbLeft.Items.Add(s); foreach(strings inchklbLeft.Items) chklbRight.Items.Remove(s); }

  16. privatevoidbtnRemoveAll_Click (object sender, EventArgs e) { chklbLeft.Items.AddRange (chklbRight.Items); chklbRight.Items.Clear(); }

  17. Menu (2 ways to use) MenuStrip MainMenu MenuItem ToolStripMenuItem Menu Property MainMenuStrip Property

  18. I would like to tell you : using MainMenuis the basic Menu. In this case, I will demo add Menu at Runtime for you. Please see next slide !

  19. Coding to create Menu at Runtime

  20. privateMainMenumainMenuBar; privateMenuItemmenuFile, menuEdit, menuFileNew, menuFileOpen, menuFileExit, menuEditCut, menuEditCopy, menuEditPaste; privatevoidcreateMenu() { mainMenuBar= newMainMenu(); this.Menu= mainMenuBar; menuFile=newMenuItem("File"); menuFileNew= newMenuItem("New"); menuFileOpen= newMenuItem("Open"); menuFileExit= newMenuItem("Exit"); menuFile.MenuItems.Add(menuFileNew); menuFile.MenuItems.Add(menuFileOpen);

  21. privatevoidcreateMenu(){…… • menuFile.MenuItems.Add("-"); • menuFile.MenuItems.Add(menuFileExit); • mainMenuBar.MenuItems.Add(menuFile); • menuEdit= newMenuItem("Edit"); • menuEditCut= newMenuItem("Cut"); • menuEditCopy= newMenuItem("Copy"); • menuEditPaste= newMenuItem("Paste"); • menuEdit.MenuItems.AddRange(newMenuItem[] { menuEditCut,menuEditCopy,menuEditPaste}); • mainMenuBar.MenuItems.Add(menuEdit); • attachEvents();}

  22. private void attachEvents() { menuFileNew.Click += process_MenuClick; menuFileOpen.Click += process_MenuClick; menuFileExit.Click += process_MenuClick; menuEditCut.Click += process_MenuClick; menuEditCopy.Click += process_MenuClick; menuEditPaste.Click += process_MenuClick; }

  23. privatevoidprocess_MenuClick (object sender, EventArgs e) { if(sender.Equals(menuFileExit)) { Application.Exit(); } } privatevoidfrmMenuBasic_Load (object sender, EventArgs e) {createMenu(); }

  24. MenuStrip

  25. Designer Click on button to add MenuItem

  26. Click Add button to add new MenuItem Text to Display Click here to add Sub MenuItem MenuItem’s Name

  27. Image Icon Text to Display Click here to add Sub MenuItem MenuItem’s Name

  28. We could add MenuItem direct on the Windows Form. Enter Name in the “Type Here”

  29. Add Event for each MenuItem

  30. Image List Drag & Drop

  31. Gets the color depth of the image list Gets the ImageList. ImageCollectionfor this image list. See Next Slide Gets or sets the size of the images in the image list

  32. Click Add button to insert Image into Collection

  33. Select image & click Open

  34. MenuStrip At Runtime

  35. privateMenuStripmenuBar; privateToolStripMenuItemmenuFile, menuEdit, menuFileNew, menuFileOpen, menuFileExit, menuEditCut, menuEditCopy, menuEditPaste;

  36. privatevoidcreateMenu() {menuBar= newMenuStrip(); menuBar.Font= newFont("arial", 36, FontStyle.Bold, GraphicsUnit.Pixel); this.MainMenuStrip= menuBar; menuFile = newToolStripMenuItem("File"); menuFileNew= newToolStripMenuItem("New"); menuFileNew.Image= imageList1.Images[0];

  37. menuFileOpen = newToolStripMenuItem("Open"); ToolStripSeparatorsp = newToolStripSeparator(); menuFileExit= newToolStripMenuItem("Exit"); menuFileExit.Image= imageList1.Images[1]; menuFile.DropDownItems.Add( menuFileNew); menuFile.DropDownItems.Add( menuFileOpen);

  38. menuFile.DropDownItems.Add(sp); menuFile.DropDownItems.Add( menuFileExit); menuEdit= newToolStripMenuItem("Edit"); menuEditCut= newToolStripMenuItem("Cut"); menuEditCopy= newToolStripMenuItem("Copy"); menuEditPaste= newToolStripMenuItem("Paste");

  39. menuEdit.DropDownItems.AddRange(newToolStripItem[] { menuEditCut,menuEditCopy, menuEditPaste}); menuBar.Items.AddRange(newToolStripItem[] { menuFile,menuEdit}); this.Controls.Add(menuBar); attachEvents(); } private void attachEvents() {menuFileExit.Click += processClick; }

  40. privatevoidprocessClick (object o, EventArgs e) { if (o.Equals(menuFileExit)) Application.Exit(); } privatevoidfrmMenuStrip_Load (object sender, EventArgs e) { createMenu(); }

  41. ContextMenuStrip Drag & Drop into the FORM

  42. ImageScalingSize to set Width, Height Icon Click Items (Collection) to add MenuItem

  43. As the same MenuStrip

  44. 1.Choose button 2.Set ContextMenuStrip 3.Attach event as the same MenuStrip

  45. ToolStripContainer&ToolStrip

  46. ToolStripContainer

More Related