Guest ronswens Posted March 18, 2005 Report Posted March 18, 2005 I have full screen app so to delete soft keys I set Menu to null. But I still need to show MainMenu by pressing right soft key. Is it possible?
Guest edgecrush3r Posted March 24, 2005 Report Posted March 24, 2005 I have full screen app so to delete soft keys I set Menu to null. But I still need to show MainMenu by pressing right soft key. Is it possible? <{POST_SNAPBACK}> Yepps... That's possible: You need to capture the keypress from the Form, and then (re)-assign the Mainmenu1 to menu if the right key (F2) is pressed. ------- using System; using System.Drawing; using System.Collections; using System.Windows.Forms; using System.Data; namespace FullscreenWithRuntimeMenu { /// /// Summary description for Form1. /// public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.MenuItem menuItem1; private System.Windows.Forms.Label label1; private System.Windows.Forms.Label label2; private System.Windows.Forms.MainMenu mainMenu1; public Form1() { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // } /// /// Clean up any resources being used. /// protected override void Dispose( bool disposing ) { base.Dispose( disposing ); } #region Windows Form Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.mainMenu1 = new System.Windows.Forms.MainMenu(); this.menuItem1 = new System.Windows.Forms.MenuItem(); this.label1 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label(); // // mainMenu1 // this.mainMenu1.MenuItems.Add(this.menuItem1); // // menuItem1 // this.menuItem1.Text = "Quit appliction"; this.menuItem1.Click += new System.EventHandler(this.menuItem1_Click); // // label1 // this.label1.Font = new System.Drawing.Font("Nina", 8.25F, System.Drawing.FontStyle.Regular); this.label1.Location = new System.Drawing.Point(16, 16); this.label1.Size = new System.Drawing.Size(136, 28); this.label1.Text = "Use right action key to enable menu"; // // label2 // this.label2.Font = new System.Drawing.Font("Nina", 8.25F, System.Drawing.FontStyle.Bold); this.label2.Location = new System.Drawing.Point(16, 52); this.label2.Size = new System.Drawing.Size(136, 16); // // Form1 // this.Controls.Add(this.label2); this.Controls.Add(this.label1); this.Menu = this.mainMenu1; this.Text = "Form1"; this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.Form1_Keypress); this.Load += new System.EventHandler(this.Form1_Load); } #endregion /// /// The main entry point for the application. /// static void Main() { Application.Run(new Form1()); } private void Form1_Load(object sender, System.EventArgs e) { this.Menu = null; } private void Form1_Keypress(object sender, System.Windows.Forms.KeyEventArgs e) { this.label2.Text= "You pressed: " + e.KeyCode.ToString(); if (e.KeyCode==Keys.F2) this.Menu = this.mainMenu1; } private void menuItem1_Click(object sender, System.EventArgs e) { this.Close(); } } }
Guest ronswens Posted March 24, 2005 Report Posted March 24, 2005 Thanks for asnwer edgecrush3r, but I'm afraid I was inaccurate in my question. I'll explain. I have 2 states of my app - full-screen mode and window-screen mode with the menu with several commands. What I want is in the full-screen mode after pressing a right soft-key the menu with commands appears just like it appears after pressing right soft-key in the window-screen mode. And the menu disappears after chosing any command from the menu and I get right to full-screen mode. Is it still possible?
Guest edgecrush3r Posted March 24, 2005 Report Posted March 24, 2005 Thanks for asnwer edgecrush3r, but I'm afraid I was inaccurate in my question. I'll explain. I have 2 states of my app - full-screen mode and window-screen mode with the menu with several commands. What I want is in the full-screen mode after pressing a right soft-key the menu with commands appears just like it appears after pressing right soft-key in the window-screen mode. And the menu disappears after chosing any command from the menu and I get right to full-screen mode. Is it still possible? <{POST_SNAPBACK}> Ofcourse.. The example did half of the job already.. If you want to hide the menu again after the selection, just use: this.Menu = null; again after you have invoked your menuItem_event. Here's the code: using System; using System.Drawing; using System.Collections; using System.Windows.Forms; using System.Data; namespace FullscreenWithRuntimeMenu { /// /// Summary description for Form1. /// public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.MenuItem menuItem1; private System.Windows.Forms.Label label1; private System.Windows.Forms.Label label2; private System.Windows.Forms.MenuItem menuItem2; private System.Windows.Forms.MenuItem menuItem3; private System.Windows.Forms.MenuItem menuItem4; private System.Windows.Forms.MainMenu mainMenu1; public Form1() { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // } /// /// Clean up any resources being used. /// protected override void Dispose( bool disposing ) { base.Dispose( disposing ); } #region Windows Form Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.mainMenu1 = new System.Windows.Forms.MainMenu(); this.menuItem1 = new System.Windows.Forms.MenuItem(); this.label1 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label(); this.menuItem2 = new System.Windows.Forms.MenuItem(); this.menuItem3 = new System.Windows.Forms.MenuItem(); this.menuItem4 = new System.Windows.Forms.MenuItem(); // // mainMenu1 // this.mainMenu1.MenuItems.Add(this.menuItem1); this.mainMenu1.MenuItems.Add(this.menuItem2); // // menuItem1 // this.menuItem1.Text = "quit"; this.menuItem1.Click += new System.EventHandler(this.menuItem1_Click); // // label1 // this.label1.Font = new System.Drawing.Font("Nina", 8.25F, System.Drawing.FontStyle.Regular); this.label1.Location = new System.Drawing.Point(16, 16); this.label1.Size = new System.Drawing.Size(136, 28); this.label1.Text = "Use right action key to enable menu"; // // label2 // this.label2.Font = new System.Drawing.Font("Nina", 8.25F, System.Drawing.FontStyle.Bold); this.label2.Location = new System.Drawing.Point(16, 52); this.label2.Size = new System.Drawing.Size(136, 16); // // menuItem2 // this.menuItem2.MenuItems.Add(this.menuItem3); this.menuItem2.MenuItems.Add(this.menuItem4); this.menuItem2.Text = "action"; // // menuItem3 // this.menuItem3.Text = "do stuff"; this.menuItem3.Click += new System.EventHandler(this.menuItem3_Click); // // menuItem4 // this.menuItem4.Text = "do more stuff"; this.menuItem4.Click += new System.EventHandler(this.menuItem4_Click); // // Form1 // this.Controls.Add(this.label2); this.Controls.Add(this.label1); this.Menu = this.mainMenu1; this.Text = "Form1"; this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.Form1_Keypress); this.Load += new System.EventHandler(this.Form1_Load); } #endregion /// /// The main entry point for the application. /// static void Main() { Application.Run(new Form1()); } private void Form1_Load(object sender, System.EventArgs e) { this.Menu = null; } private void Form1_Keypress(object sender, System.Windows.Forms.KeyEventArgs e) { this.label2.Text= "You pressed: " + e.KeyCode.ToString(); if (e.KeyCode==Keys.F2) this.Menu = this.mainMenu1; } private void menuItem1_Click(object sender, System.EventArgs e) { this.Close(); } private void menuItem3_Click(object sender, System.EventArgs e) { // put your code here // ... this.Menu = null; } private void menuItem4_Click(object sender, System.EventArgs e) { // put your code here // ... this.Menu = null; } } }
Guest ronswens Posted March 26, 2005 Report Posted March 26, 2005 So I need to insert "this.Menu = null;" in every click command handler? Ok, I guessed there's no other way but how to get rid of double press of F2 (a right soft key) to show the command list? I must press it once to mainmenu appears and second time to show the command list. Is there a way to show the list right after F2 was pressed for the first time?
Guest edgecrush3r Posted March 29, 2005 Report Posted March 29, 2005 So I need to insert "this.Menu = null;" in every click command handler? Ok, I guessed there's no other way but how to get rid of double press of F2 (a right soft key) to show the command list? I must press it once to mainmenu appears and second time to show the command list. Is there a way to show the list right after F2 was pressed for the first time? <{POST_SNAPBACK}> Yupps... Removing Items from the MainMenu collection is not supported on the Smartphone device, therefore theres no other way than disposing, and re-assigning.. Ofcourse you can easily create a more versatile control by extending the MainMenu class, and assign the collection to a temp menuItemCollection.. On the second question,.. Did you try to fire the Popup event manually ?
Guest ronswens Posted March 29, 2005 Report Posted March 29, 2005 Yupps... Removing Items from the MainMenu collection is not supported on the Smartphone device, therefore theres no other way than disposing, and re-assigning.. Ofcourse you can easily create a more versatile control by extending the MainMenu class, and assign the collection to a temp menuItemCollection.. On the second question,.. Did you try to fire the Popup event manually ? <{POST_SNAPBACK}> No, I don't know how. I know that I can show ContextMenu using ContextMenu.Show but then I need to have a control to bind a ContextMenu to it. But how to show MainMenu?
Guest edgecrush3r Posted March 29, 2005 Report Posted March 29, 2005 No, I don't know how. I know that I can show ContextMenu using ContextMenu.Show but then I need to have a control to bind a ContextMenu to it. But how to show MainMenu? <{POST_SNAPBACK}> Seems that this popup-behaviour cannot be implemented using the MainMenu, and thus you will be stuck pressing F2 twice. If you found a way.. let me know :D
Guest ronswens Posted March 29, 2005 Report Posted March 29, 2005 Only if use P/Invoke to keybd_event(), I hate this. Thanks for help edgecrush3r :D
Guest edgecrush3r Posted March 30, 2005 Report Posted March 30, 2005 Only if use P/Invoke to keybd_event(), I hate this. Thanks for help edgecrush3r :D <{POST_SNAPBACK}> Not the must elegan t way indeed, but heY if it works, it works !!... Can you share the interop code with us please ? Thanks, Tony Tromp
Guest ronswens Posted March 30, 2005 Report Posted March 30, 2005 Sure! [system.Runtime.InteropServices.DllImport("coredll.dll")] private static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo); const int VK_F2 = 0x71; protected override void onkeydown(KeyEventArgs e) { switch(e.KeyCode) { case Keys.F2: //Quit full-screen WindowState = FormWindowState.Normal; FormBorderStyle = FormBorderStyle.Sizable; Menu = menu; //Send right soft key press and release keybd_event(VK_F2,0, 0, 0); keybd_event(VK_F2,0, 2, 0); break; } }
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now