Confused about Identical Icon files in Windows Phone 8 apps - c#

Why are there 2 of the same icons in Visual Studio?
If you type:
<shell:ApplicationBarIconButton Text="new document" IconUri="" /> and then open the Properties pane and open up the ComboBox for the ApplicationBarIconButton element, you'll notice that this comb box has an add button and a new button icon. And when you look at both icons - they're the same.
But why?
I know that, in context, both new, and add, can have different meanings/perform different actions:
E.g. New could create a new document, while add could attach something/add something to the currently-open document.
But then if that's the reasoning - then both icons should be different as this could potentially lead to confusion because the default state of the Application bar icon's is set such that the text of the icon is not visible unless you tap on the ... to the bottom right of the screen. So if I had both an add and a new button in the ApplicationBar menu, while in default state, this could be very confusing and will force the user to open the menu just to see which button is which. Which goes against the purpose of hiding the menubar text in the first place, doesn't it?

I try not to spend a whole lot of valuable development time trying to figure all the reasons as to why Microsoft decides to implement one default image over another in a development environment. It is my responsibility as the developer to choose exactly how I want the program to look and feel.
There are a lot of standard icons to choose from that come bundled with the SDK.
C:\Program Files (x86)\Microsoft SDKs\Windows Phone\v8.0\Icons\
Additionally, here is how someone can create their own custom Application Bar. One alternative button icon approach is to continuing using the standard add.png image for the New button and use the check.png image for the Add button if it is really necessary to have both types of actions on the same Application Bar.
public partial class MyPage : PhoneApplicationPage
{
public MyPage()
{
InitializeComponent();
BuildApplicationBar();
}
private void BuildApplicationBar()
{
// Set the page's ApplicationBar to a new instance of ApplicationBar.
ApplicationBar = new ApplicationBar();
ApplicationBar.Mode = ApplicationBarMode.Default;
ApplicationBar.IsVisible = true;
ApplicationBar.Opacity = 1.0;
ApplicationBar.IsMenuEnabled = true;
// Create new buttons
ApplicationBarIconButton AppBarAddButton = new ApplicationBarIconButton(new Uri("/Assets/check.png", UriKind.Relative));
AppBarAddButton.Text = "Add";
AppBarAddButton.Click += new EventHandler(AppBarAddButton_Click);
ApplicationBar.Buttons.Add(AppBarAddButton);
ApplicationBarIconButton AppBarNewButton = new ApplicationBarIconButton(new Uri("/Assets/add.png", UriKind.Relative));
AppBarNewButton.Text = "New";
AppBarNewButton.Click += new EventHandler(AppBarNewButton_Click);
ApplicationBar.Buttons.Add(AppBarNewButton);
}
private async void AppBarAddButton_Click(object sender, EventArgs e)
{
//TODO: Do something for the add click action
}
private async void AppBarNewButton_Click(object sender, EventArgs e)
{
//TODO: Do something for the new click action
}
}

Related

C# Winforms change taskbar icon

I have an old legacy system that uses Winforms and is published with the built in One click,
I look after 3 different installs and each one has its own database it connects to, so its been set up that when a different system is click, it check isCompany1 and will set the Favicon accordingly
so when depoyment is done in the application window the Icon and Manifest is set to the correct ICO, when installed the .exe icon will be what is set there,
However i am trying to bring these all inline as when we debug a drop asks which database we would like to connect to, and depending on that it will set things up differently.
When running in VS the icons in the taskbar will change accoring to the dynamic Favicon however when its depolyed with this new selection it wont change, (it will change once on first load, then wont again)
The issue is some users need access to the different instances so would like different icons at the bottom, but its not changing the task menu, but everything else such as ALT-TAB and the control panel icon is changing,
all forms link into a baseform and call this :
if (App.IsCompany1)
{
this.Icon = new Icon("Resources\\Company1.ico");
}
else if (App.Company2)
{
this.Icon = new Icon("Resources\\Company2.ico");
}
else if (App.Company3)
{
this.Icon = new Icon("Resources\\Company3.ico");
}
AS i said this will change everything but not the Taskbar, but will from VS debugging,
I have made sure the .ico has all sizes, by writing their sizes on each one, and they display correctly the Taskbar and ALT-TAB both use 32x32
If it's any consolation, I couldn't reproduce your complaint.
I put 3 icons in resources, a single button on a form, this code:
private int iconum = 0;
private Icon[] icons = new[] { Properties.Resources.icon1, Properties.Resources.icon2, Properties.Resources.icon3 };
private void button1_Click(object sender, EventArgs e)
{
this.Icon = icons[iconum++ % icons.Length];
}
And it cycled through the icons in the main form title bar and the windows task bar over and over on every button click (made sure to run a release built exe too, not a debug start):
Note: the thing in the top right is my taskbar

C# - VisualStyles.VisualStyleState.NonClientAreaEnabled shows a different dialog with OpenFileDialog call

Setting VisualStyles.VisualStyleState.NonClientAreaEnabled in code shows a completely different dialog for OpenFileDialog call than when done without a VisualStyleState. The drop down for "View Menu" shows a vertical bar without text and the left browser pane is gone.
Image showing problem with Visual Style State set
In our application we need to set Styles as we have developed custom ones.
Issue reproducible on Windows 10 Build 1709, .Net 4.6.1 and default C# forms application. Also reproduced on Windows 10 build 1809. Works fine with all earlier versions of Windows.
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Application.VisualStyleState = System.Windows.Forms.VisualStyles.VisualStyleState.NonClientAreaEnabled;
}
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog fileDialog = new OpenFileDialog();
fileDialog.Multiselect = false;
fileDialog.CheckFileExists = true;
fileDialog.Filter = " (*.sql)|*.sql";
fileDialog.ShowDialog();
}
}
Without VisualStyleState set, the OpenFileDialog shows a completely different UI, with browser pane on the left side and all drop downs work as expected.
Image showing default behaviour of OpenFileDialog
Any pointers to fix this issue would be helpful.
In one situation a dialog is rendered as an old style dialog and the other one as so-called “Vista-style” dialog:
old style
Vistay style
Here's the code the drives this decision:
https://referencesource.microsoft.com/#System.Windows.Forms/winforms/Managed/System/WinForms/FileDialog.cs,986
A type of a dialog depends on whether VisualStyleState.ClientAreaEnabled is set or not. Because you set the style to VisualStyleState.NonClientAreaEnabled the app falls back to the old-style.
There is AutoUpgradeEnabled property that allow rendering the dialog as Vista-style, you could try setting it to true and see if it helps.

Implementing activeX control to view PowerPoint slides in Windows forms using c#, not showing control

I'm working on a project and I need to embed a PowerPoint viewer in windows forms. I'm using the following activeX control: http://www.daolnwod.com/free-powerpoint-viewer-activex.html.
I activated the control to be used with the form designer's toolbox and dragged it into my form. I then edited the code in the InitializeComponent() method to the following:
this.axPowerPointViewer1 = new AxPOWERPOINTVIEWERLib.AxPowerPointViewer();
((System.ComponentModel.ISupportInitialize)(this.axPowerPointViewer1)).BeginInit();
this.axPowerPointViewer1.Enabled = true;
this.axPowerPointViewer1.Location = new System.Drawing.Point(0, 0);
this.axPowerPointViewer1.Name = "axPowerPointViewer1";
this.axPowerPointViewer1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axPowerPointViewer1.OcxState")));
this.axPowerPointViewer1.Size = new System.Drawing.Size(925, 573);
this.axPowerPointViewer1.TabIndex = 5;
//this.axPowerPointViewer1.CreateControl();
this.Controls.Add(this.axPowerPointViewer1);
((System.ComponentModel.ISupportInitialize)(this.axPowerPointViewer1)).EndInit();
And in my Forms constructor
public Form1()
{
InitializeComponent();
axPowerPointViewer1.Show();
bool loaded = axPowerPointViewer1.LoadFile(#"C:\Debug\test2.ppt"); // loaded = false
string z = axPowerPointViewer1.GetSlideCount().ToString();
}
However, when I'm opening the form nothing shows up. The code compiles but I can't see my test slide that I've been working on. I have created 2 buttons for 'Previous' and 'Next' slides but debugging gives me a slide location of 0 every time so something must be wrong and I can't seem to find it.
UPDATE
The problem has been solved. It seems I didn't call axPowerPointviewer1.InitControl(). It still has a few troubles, sometimes it won't display the first slide at startup. If things keep running smoothly I'll post an answer to this problem.
The problem is in initialising the control. In order for the control to fully function you need to call the InitControl() method so call calling the following code should make the program work:
private void Form1_Load(object sender, EventArgs e)
{
this.axPowerPointViewer1.InitControl();
}

Change content of WPF Window

When I click on a Button on my navigation bar, a new Window opens. For example:
private void btFinanzen_Click(object sender, RoutedEventArgs e)
{
Finanz mw = new Finanz(login);
mw.Show();
}
Now, I don´t want to show it in a new window. Instead of that, I want it to be shown at the same window. I tried with the following:
private void btFinanzen_Click(object sender, RoutedEventArgs e)
{
Finanz mw = new Finanz(login);
//mw.Show();
this.Content = Finanz f;
}
but it failed.
What I should say is, that I´ve many of different windows now and want them all to be shown at one window - each by clicking a different button.
How can I manage this?
What you have to do is to use a UserControl rather than a Window for your replaceable content. Add a new UserControl for each possible content you want to show in this.Content to your project. Add the content you had previously in the second window to the appropriate UserControl. After that you can simply instantiate the new control in your code and assign it to your content area of your main Window.
For example you create a UserControl ctlFinanz with the content of your previous Finanz window. Now you simply write:
this.Content = new ctlFinanz(login);
That's all :-)
I had the same problem and decided to create a seperate usercontrol for every window, put them in my wpf and set the visibility of all windows except the active one to Collapsed.
To me, this sounds like place to use a frame with pages. Instead of making lots of windows, make one window with a frame, then put the content into pages. Then all you have to do is change the frame's .Content to a different page each time you press a navigation button.
Create a main content with a UserControl that I set into the window constructor. And then I change the content with other UserControl depending on your needs.
MainWindow constructor:
this.Content = new UserControlMainContent();
From UserControlMainContent, when I click on a button by example:
Window window = Window.GetWindow(this); // Get the main window
window.Content = new OtherUserControlContent();

(VB.NET / C#) How to create Vista-like style MenuStrip? [duplicate]

I noticed that adding a MenuStrip (from the Toolbox) to my form design doesn't yield a menu bar like the one seen in many native Windows applications. Instead I get a menu bar like Visual Studio's own. None of the style settings for MenuStrip appear to mimic the much more common native menu bar.
Is there a way to add a menu bar to my Windows Forms application that looks the same as the one you see in Notepad, Task Manager and others? (Preferably with the designer, but I wouldn't mind adding it programmatically either.)
Screenshot for illustration:
Go to your Toolbox, right click anywhere inside and select "Choose Items".
When the dialog loads and appears, scroll down til you see MainMenu. Add that to the toolbox, and you've got yourself a native menu bar!
You can do this by setting your form's Menu property, like this:
private void Form1_Load(object sender, EventArgs e)
{
this.Menu = new MainMenu();
MenuItem item = new MenuItem("File");
this.Menu.MenuItems.Add(item);
item.MenuItems.Add("Save", new EventHandler(Save_Click));
item.MenuItems.Add("Open", new EventHandler(Open_Click));
item = new MenuItem("Edit");
this.Menu.MenuItems.Add(item);
item.MenuItems.Add("Copy", new EventHandler(Copy_Click));
item.MenuItems.Add("Paste", new EventHandler(Paste_Click));
// etc ...
}
private void Save_Click(object sender, EventArgs e)
{
// save
}
These menus will look like "normal" system menus.
I couldn't find any designer support for this, though. In my defense, I didn't try real hard.
Instead of using a the MainMenu component you can create your own renderer for the MenuStrip component. The advantage here is being able to add images to MenuStripItem objects. Here is the pastebin for the custom renderer:
NativeRenderer
There are different themes that can be applied in the constructor of the renderer. Try them all to see the native themes. To use this renderer simply set the instance to the MenuStrip Renderer property:
menuStrip.Renderer = new NativeRenderer([theme]);
I normally set the MenuStrip's RenderMode to System which gives a minimalist, single colour menu (no gradients or anything decadent like that).
If that does not go far enough, then you'll likely have to jump through some low-level hoops to get what you want.

Categories

Resources