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.
Related
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
I'm developing a WPF application that's meant to live in the tool tray, so it doesn't involve any windows. Right-clicking the tool tray icon brings up a menu with a Configure Report Path... option, and I'd like to display a folder browser dialog to the user when this is clicked:
What I'm finding is that when the option is selected, a dialog opens and immediately closes unless I assign some window to Application.Current.MainWindow and show it before opening the dialog. This is the code I'm using:
public CounterIconViewModel(IMessenger messenger)
{
void ConfigureReportPath()
{
// Application window must be created and displayed.
Application.Current.MainWindow = new Window();
Application.Current.MainWindow.Show();
var browseDialog = new VistaFolderBrowserDialog { ShowNewFolderButton = false };
if (browseDialog.ShowDialog() != true)
{
return;
}
// (Separate issue) Command doesn't execute unless I comment out the line below.
//messenger.Send(browseDialog.SelectedPath, "ReportPath");
}
ConfigureReportPathCommand = new RelayCommand(ConfigureReportPath);
ExitApplicationCommand = new RelayCommand(Application.Current.Shutdown);
}
In this case I'm using VistaFolderBrowserDialog from Ookii.Dialogs.Wpf, but I've tried the same thing with another WPF browser dialog and notice identical behaviour.
Is there a reason why a browser dialog seems to require a window to be displayed to remain open, and any workarounds?
Update
I've found that if I initialize and pass an instance of Window to browseDialog.ShowDialog, the dialog remains open without me having to assign the main application window and display it:
if (browseDialog.ShowDialog(new Window()) != true)
I don't understand why this works. I'll post this as an answer if no others appear so that at least people in a similar situation are aware of this workaround.
Update 2
The other dialog I tested it with was CommonOpenFileDialog from Microsoft.WindowsApiCodePack-Shell:
var browseDialog = new CommonOpenFileDialog { IsFolderPicker = true };
browseDialog.ShowDialog();
My tool tray icon displays a rich tool-tip (a custom UserControl) if I hover over it, and with this browser dialog I found that:
If I hover over the icon to make the tool-tip display, then the browser dialog works fine when I try to open it on the first and every subsequent attempt.
If I try to open the browser dialog before displaying the tool-tip display, the browser dialog opens and closes immediately on the first try, but then remains open on every subsequent attempt.
This dialog also accepts a Window instance in ShowDialog but it makes no difference if I pass one or not.
My workaround (initializing and passing a blank window to the Ookli dialog browser) seems to work fine regardless of whether I first bring up the tool-tip, so I'm sticking with that for the time being.
I'm a newbie with Visual Studio Express 2013 and C#. I've borrowed a simple C# Windows application which builds and runs fine, and now I want to add some objects to the main form.
I select an object from the Toolbox, then click in the Designer on my main form where I want it to appear. This works fine for some simple objects like Label, but when I select an OpenFileDialog object nothing appears on my form. An OpenFileDialog "box" appears in a bar below my form instead, and I can't drag it to my form (I get a slashed circle).
I'm surely missing something simple. Thanks for any help.
You cannot drag an OpenFileDialog to the form because it is a non visual control.
To add an OpenFileDialog,just double click the control in the toolbox.That will add it to the form.Now to show the dialog you have to use OpenFileDialog.ShowDialog() in the code behind.Here is an example which shows the dialog on the click of a button.:
private void button1_Click(object sender, EventArgs e)
{
openFileDialog1.Filter = "Text Files (.txt)|*.txt|All Files (*.*)|*.*";
DialogResult result= openFileDialog1.ShowDialog();
if(result==DialogResult.OK)
using (StreamReader reader = new StreamReader(openFileDialog1.FileName))
{
string s = reader.ReadLine();
}
}
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
}
}
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();
}