Ho to make Secondary Commands in C# in windows phone 8.1 (winprt) app?
//WINRT:
CommandBar CommandBarObject = new CommandBar();
AppBarButton FirstBtn = new AppBarButton() { Icon = new BitmapIcon() { UriSource = new Uri("ms-appx:///Assets/first.png") } };
FirstBtn.Label = "First";
FirstBtn.Click += FirstBtn_Click;
FirstBtn.IsEnabled = true;
CommandBarObject.PrimaryCommands.Add(FirstBtn);
CommandBarObject.SecondaryCommands.Add(secondaryCommand);
How to make this secondaryCommand now?
Just put there AppBarButton:
CommandBar CommandBarObject = new CommandBar();
AppBarButton FirstBtn = new AppBarButton() { Icon = new BitmapIcon() { UriSource = new Uri("ms-appx:///Assets/first.png") } };
FirstBtn.Label = "First";
FirstBtn.Click += FirstBtn_Click;
FirstBtn.IsEnabled = true;
AppBarButton secondaryCommand = new AppBarButton() { Label = "Second", IsEnabled = true } };
secondaryCommand.Click += FirstBtn_Click;
CommandBarObject.PrimaryCommands.Add(FirstBtn);
CommandBarObject.SecondaryCommands.Add(secondaryCommand);
Related
I have created menu dynamically.But I don't know how to handle events of menu Item.Please Let me know if anyone have solution.Thanks in Advance.
ToolStripMenuItem master,transaction,report,exit;
private void Menu1_Load(object sender, EventArgs e)
{
master = new ToolStripMenuItem("Master");
menuStrip1.Items.Add(master);
master.DropDownItems.Add("Party Master");
master.DropDownItems.Add("Item Master");
master.DropDownItems.Add("Tax Master");
master.Click += MenuClicked;
transaction = new ToolStripMenuItem("Transaction");
menuStrip1.Items.Add(transaction);
transaction.DropDownItems.Add("Inward");
transaction.DropDownItems.Add("Inoice");
transaction.DropDownItems.Add("Daily Expense");
report = new ToolStripMenuItem("Report");
menuStrip1.Items.Add(report);
report.DropDownItems.Add("Master Report");
report.DropDownItems.Add("Transaction Report");
report.DropDownItems.Add("Daily Expense Report");
exit = new ToolStripMenuItem("Exit");
menuStrip1.Items.Add(exit);
}
private void MenuClicked(object o,EventArgs e)
{
if ((((ToolStripMenuItem)o).Text) == "Party Master")
{
Master.PartyMaster p = new Master.PartyMaster();
p.Show();
}
}`
`// Master
master.DropDownItems.
AddRange(new System.Windows.Forms.ToolStripItem[]
{
partyMaster,
itemMaster,
taxMaster
}
);
master.Name = "Master";
master.Size = new System.Drawing.Size(125, 20);
master.Text = "Master";
master.Click += new System.EventHandler(master_Click);
// Party Master
partyMaster.Name = "PartyMaster";
partyMaster.Size = new System.Drawing.Size(152, 22);
partyMaster.Text = "PartyMaster";
partyMaster.Click += new System.EventHandler(partyMaster_Click);
// Item Master
itemMaster.Name = "ItemMaster";
itemMaster.Size = new System.Drawing.Size(152, 22);
itemMaster.Text = "ItemMaster";
// Tax Master
taxMaster.Name = "TaxMaster";
taxMaster.Size = new System.Drawing.Size(152, 22);
taxMaster.Text = "TaxMaster"; //`
Or more dynamically with List and for loop.
List<ToolStripMenuItem> items = new List<ToolStripMenuItems>();
And loop to add more items to the Menu
ToolStripMenuItem item = new ToolStripMenuItem();
items.Add(item);
item.Click += new EventHandler(MenuClicked); // if you want to stick with only one function
Try add your dropdown items this way:
ToolStripItem partyMaster = new ToolStripMenuItem() { Text = "Party Master" };
partyMaster.Click += MenuClicked;
ToolStripItem itemMaster = new ToolStripMenuItem() { Text = "Item Master" };
itemMaster.Click += MenuClicked;
ToolStripItem taxMaster = new ToolStripMenuItem() { Text = "Tax Master" };
taxMaster.Click += MenuClicked;
master.DropDownItems.Add(partyMaster);
master.DropDownItems.Add(itemMaster);
master.DropDownItems.Add(taxMaster);
I try to add a panel to Form, but it never appears. But When I change its type e.g. on TextBox it apears. Anyone know why?
HidePanel = new Panel();
HidePanel.ForeColor = Color.Red;
HidePanel.BackColor = Color.Green;//Form.BackColor;
HidePanel.Location = new System.Drawing.Point(531, 181);
HidePanel.Name = "HidePanel";
HidePanel.Size = new System.Drawing.Size(200, 100);
HidePanel.Visible = true;
HidePanel.TabIndex = 12;
HidePanel.BringToFront();
Form.Controls.Add(HidePanel);
you used Form and it's not true, you should use this instead of Form, try this code.
HidePanel = new Panel();
HidePanel.ForeColor = Color.Red;
HidePanel.BackColor = Color.Green;//Form.BackColor;
HidePanel.Location = new System.Drawing.Point(531, 181);
HidePanel.Name = "HidePanel";
HidePanel.Size = new System.Drawing.Size(200, 100);
HidePanel.Visible = true;
HidePanel.TabIndex = 12;
HidePanel.BringToFront();
this.Controls.Add(HidePanel);
update:
Form2 frm = new Form2();
Panel HidePanel = new Panel();
HidePanel.ForeColor = Color.Red;
HidePanel.BackColor = Color.Green;//Form.BackColor;
HidePanel.Location = new System.Drawing.Point(531, 181);
HidePanel.Name = "HidePanel";
HidePanel.Size = new System.Drawing.Size(200, 100);
HidePanel.Visible = true;
HidePanel.TabIndex = 12;
HidePanel.BringToFront();
frm.Controls.Add(HidePanel);
frm.Show();
I put this code in click event of button1, which declared in form1.
Icons do not appear in ApplicationBar.
MainPage.xaml.cs
// Конструктор
public MainPage()
{
InitializeComponent();
// Локализация ApplicationBar
BuildLocalizedApplicationBar();
}
// ApplicationBar
private void BuildLocalizedApplicationBar()
{
// Установка нового экземпляра ApplicationBar.
ApplicationBar = new ApplicationBar();
// Задаем опции
ApplicationBar.Mode = ApplicationBarMode.Default;
ApplicationBar.Opacity = 1.0;
ApplicationBar.IsVisible = true;
ApplicationBar.IsMenuEnabled = true;
// Кнопка "Add"
ApplicationBarIconButton Add = new ApplicationBarIconButton(new Uri("/Assets/AppBar/Add.png", UriKind.Relative));
Add.Text = AppResources.AppBarAdd;
ApplicationBar.Buttons.Add(Add);
Add.Click += new EventHandler(Button_Add_Click);
// Кнопка "Edit"
ApplicationBarIconButton Edit = new ApplicationBarIconButton(new Uri("/Assets/AppBar/Edit.png", UriKind.Relative));
Edit.Text = AppResources.AppBarEdit;
ApplicationBar.Buttons.Add(Edit);
Edit.Click += new EventHandler(Button_Edit_Click);
// Кнопка "Delete"
ApplicationBarIconButton Delete = new ApplicationBarIconButton(new Uri("/Assets/AppBar/Delete.png", UriKind.Relative));
Delete.Text = AppResources.AppBarDelete;
ApplicationBar.Buttons.Add(Delete);
Delete.Click += new EventHandler(Button_Delete_Click);
// Кнопка "Connect"
ApplicationBarIconButton Connect = new ApplicationBarIconButton(new Uri("/Assets/AppBar/Connect.png", UriKind.Relative));
Connect.Text = AppResources.AppBarConnect;
ApplicationBar.Buttons.Add(Connect);
Connect.Click += new EventHandler(Button_Connect_Click);
}
Icons in the folder / Assets / AppBar / is, standard icons, pulled out of most SDK, size 76x76, for Dark theme.
The problem on the emulator and on the phone.
I am having mother form now, I want to create a new form programatically. I created the new form but I couldn't add controls to the form.
private void CreateWindows()
{
newWindow = new Form();
Application.Run(newWindow);
newWindow.Activate();
newWindow.Size = new System.Drawing.Size(40, 40);
Label label1 = new Label();
newWindow.Controls.Add(label1);
label1.Text = "HI";
label1.Visible = true;
label1.Size = new System.Drawing.Size(24, 24);
label1.Location = new System.Drawing.Point(24, 24);
}
I have tried the codes above, the new form showed but I couldn't see the label1.
I appreciate any helps.
Try putting the add controls after setting up the properties of label and then Show the new window.
private void CreateWindows()
{
newWindow = new Form();
newWindow.Activate();
newWindow.Size = new System.Drawing.Size(40, 40);
Label label1 = new Label();
label1.Text = "HI";
label1.Visible = true;
label1.Size = new System.Drawing.Size(24, 24);
label1.Location = new System.Drawing.Point(24, 24);
newWindow.Controls.Add(label1);
newWindow.Show();
//use this if you want to wait for the form to be closed
//newWindow.ShowDialog();
}
First: add the controls to newWindow.Controls.
Second: Do it before Application.Run because it will show the form and then wait for it to close (note: the way the designer does it is to add them at the constructor of a class that derived from Form).
private void CreateWindows()
{
newWindow = new Form();
//Application.Run(newWindow); //Not here
//newWindow.Activate(); //Wont do anything
newWindow.Size = new System.Drawing.Size(40, 40);
Label label1 = new Label();
newWindow.Controls.Add(label1); //Good
label1.Text = "HI";
label1.Visible = true;
label1.Size = new System.Drawing.Size(24, 24);
label1.Location = new System.Drawing.Point(24, 24);
Application.Run(newWindow); //Here instead
}
Third: if you have already used Application.Run in the current thread (say because you are doing this from a form), then there is no point to call it here. Use Show or ShowDialog instead.
Also consider adding controls this way:
private void CreateWindows()
{
newWindow = new Form();
newWindow.Size = new System.Drawing.Size(40, 40);
newWindow.Controls.Add
(
new Label()
{
Text = "HI",
Visible = true,
Size = new System.Drawing.Size(24, 24),
Location = new System.Drawing.Point(24, 24)
}
);
Application.Run(newWindow);
}
I've tried several things and eventualy just put the image directly inside C:\Users\Gebruiker\Documents\Visual Studio 2012\Projects\FolderMonitor\FolderMonitor\bin\Debug. This works for now, but idealy I'd like to set the notifyIcon.Icon = new Icon("folder.ico") to an image inside a images folder in the solution. But I can't figure out how this works..
public FolderMonitorApplicationContext()
{
this.monitor = new Monitor();
notifyIcon = new NotifyIcon();
notifyIcon.Icon = new Icon("folder.ico");
notifyIcon.Text = "Folder Monitor";
notifyIcon.Visible = true;
contextMenu = new ContextMenuStrip();
openMonitor = new ToolStripMenuItem();
exitApplication = new ToolStripMenuItem();
notifyIcon.ContextMenuStrip = contextMenu;
notifyIcon.DoubleClick += NotifyIcon_DoubleClick;
openMonitor.Text = "Open";
openMonitor.Click += new EventHandler(OpenMonitor_Click);
contextMenu.Items.Add(openMonitor);
exitApplication.Text = "Exit..";
exitApplication.Click += new EventHandler(ExitApplication_Click);
contextMenu.Items.Add(exitApplication);
}
So it's currently working, but not how it i'd like it to work. Hope you can help me out here, thanks in advance.
After adding the picture file to your project, bring up the item properties by clicking on it, and pressing F4. Under Build Action, change it to "Embedded Resource".
You can access embedded resources in Stream form like this:
public FolderMonitorApplicationContext()
{
this.monitor = new Monitor();
notifyIcon = new NotifyIcon();
using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(
"<project namespace>.<folder path>" + "filename.ico"))
{
notifyIcon.Icon = new Icon(stream);
}
notifyIcon.Text = "Folder Monitor";
notifyIcon.Visible = true;
contextMenu = new ContextMenuStrip();
openMonitor = new ToolStripMenuItem();
exitApplication = new ToolStripMenuItem();
notifyIcon.ContextMenuStrip = contextMenu;
notifyIcon.DoubleClick += NotifyIcon_DoubleClick;
openMonitor.Text = "Open";
openMonitor.Click += new EventHandler(OpenMonitor_Click);
contextMenu.Items.Add(openMonitor);
exitApplication.Text = "Exit..";
exitApplication.Click += new EventHandler(ExitApplication_Click);
contextMenu.Items.Add(exitApplication);
}
Use the same method to insert the icon on the form.
To find the same code in your application to copy in your systemtray please:
check if, in the file .resx, there is the icon called with $ symbol(example:"$this.icon")
find your code to include the icon on the [name of form].desiner.cs.
example of code in my application:
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(systemtray));
trayIcon.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));