private void btnRadarFolder_Click(object sender, RoutedEventArgs e)
{
using (var dialog = new System.Windows.Forms.FolderBrowserDialog())
{
System.Windows.Forms.DialogResult result = dialog.ShowDialog();
if(result.)
}
}
The first time I tried to use the System.Windows.Forms.FolderBrowserDialog I got error that Forms don't exist. so I installed the ookii-dialogs-wpf package and once installed the errors are gone but I'm not sure what to do next. The variable result don't have an OK or any properties to continue with the dialog.
When I click the button, it's opening the dialog browser like in the old vista style, but I'm not sure how to handle it in the button/s click event.
Related
I am using .NET 4.8 WebBrowser component, while using web page that creates new window on submit, it creates new Internet Explorer process with a Tab of this new window.
This is a problem for me as what I need, is the content of this new window.
I tried using NewWindow event on WebBrowser, to e.Cancel this event and redirect WebBrowser component to desired NewWindow URL, but it does not work, as this webSite uses some form of App PostBack that returns only one time resutls.
Then I tried to use
AutoItX.WinGetText("Window Title"); //Of course I changed this to real window title
But it does not show one thing and that is content of the TabPage
Is there any way to read content of Internet Explorer tab please ?
I have tried:
AutoItX.WinGetText("Window Title"); //Of course I changed this to real window title
and also
private void webBrowser1_NewWindow(object sender, CancelEventArgs e)
{
e.Cancel = true;
webBrowser1.Navigate("url");
}
WebPage: cica.vugk.sk , Navigate to 'vlastnik spravca', fill 'prvé písmeno priezviska' to A, click 'Vytvor LV', it creates popup that I need content of and I did not find any solution how to access it using WebBrowser, or WebView2.
C# WebBrowser is forced to open in this window, and prohibited to open in a new window.
Use the load complete event to change the target value of all links and forms to "_self":
private void webBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
foreach (HtmlElement archor in this.webBrowser.Document.Links)
{
archor.SetAttribute("target", "_self");
}
foreach (HtmlElement form in this.webBrowser.Document.Forms)
{
form.SetAttribute("target", "_self");
}
}
Cancel the new window event:
private void webBrowser1_NewWindow(object sender, CancelEventArgs e)
{
e.Cancel = true;
}
WebBrowser property settings:
Set AllowWebBrowserDrop of WebBrowser to false (no drag and drop)
Set WebBrowserShortcutsEnabled of WebBrowser to false (disable shortcut keys)
Set WebBrowser's IsWebBrowserContextMenuEnabled to false (disable right-click context menu)
Is there an easy way to show an dialog when the program is started for the first time (and only the first time), for some kind of instruction or specifying settings?
You could save it as a bool in your settings and you should check at load event of first form.
Your settings file should have a setting that I called "FirstRun" do this with following steps:
Right click your Project
Click "Properties"
Click "Settings" tabpage(probably on the left)
Add setting like I did as seen in image above
Note: The Scope can be changed to "Application", if that is your application's need, since you didn't mention in your question.
Your Settings file should look like image below:
public void Form1_Load(object sender, EventArgs e)
{
if((bool)Properties.Settings.Default["FirstRun"] == true)
{
//First application run
//Update setting
Properties.Settings.Default["FirstRun"] = false;
//Save setting
Properties.Settings.Default.Save();
//Create new instance of Dialog you want to show
FirstDialogForm fdf = new FirstDialogForm();
//Show the dialog
fdf.ShowDialog();
}
else
{
//Not first time of running application.
}
}
Note: wrote this from my phone, so I couldn't compile to test
Edit: Checked code and added image from desktop.
You can have bool value in your settings file which is a "user setting" which means you can change it to true save it for this specific user.
When your application starts just check that value. If it's false show your dialog and change it to true and it will stay true.
public void Form_Load(object sender, EventArgs e)
{
if(Settings.Default.ShowDialog)
{
Settings.Default.ShowDialog = false;
Settings.Default.Save();
// show first disalog
}
// rest of code if needed
}
Here's an MSDN link on user settings:
http://msdn.microsoft.com/en-us/library/bb397750(v=vs.110).aspx
Ok, so I assume you're creating WinForms application. First of all, locate the Load event in your main Form event lists (or simply double click your Form in Designer panel). The following method stub will pop up:
public void Form1_Load(object sender, EventArgs e)
{
}
And modify it like this:
public void Form1_Load(object sender, EventArgs e)
{
MessageBox.Show("Your message here");
}
I am using the below code in visual studio to make an auto login software . The software is working fine, But the page that is displayed after login has a popup script. This forces the opening of popup url in internet explorer. I want to block the internet explorer getting opened. Can i solve this ?
private void webBrowser1_DocumentCompleted_1(object sender, WebBrowserDocumentCompletedEventArgs e)
{
webBrowser1.Navigate("https://mwcp-ekm-04.adlkerala.com:8001/");
webBrowser1.Document.GetElementById("name").InnerText = "name";
webBrowser1.Document.GetElementById("id").InnerText = "66491";
webBrowser1.Document.GetElementById("accept").InvokeMember("click");
}
You can prevent the opening of a new window (popup) by subscribing to the NewWindow event and then cancel the event itself:
private void webBrowser1_NewWindow(object sender, CancelEventArgs e)
{
e.Cancel = true;
}
I am working on a large application and am adding some drag/drop functionality to it. Specifically, I am allowing the user to drag and drop a file into the main window to open the file.
The problem is that the drag/drop operation is still allowed to happen when the main window is displaying a dialog box (for example, a properties window for an item in the currently-open file). I would rather not allow this to happen if the main window is displaying a modal dialog box. This is because loading the new file in the application while the dialog box is open would probably crash the program: the code calling the dialog box does not expect the open file to be changed while the dialog box is open (that is why the dialog box was modal...).
The main application is written in C++, but I am posting a C# sample. The symptom/behavior is the same on both platforms, but I can demonstrate it in much less code with C#. I am very familiar with both languages/platforms so I can translate any answers to the appropriate language as needed.
To demonstrate the problem with my sample code, compile and run the following C# code. It will create a "main window" that is a valid drop target. Drag and drop a file from Windows Explorer onto the main window: you should see a "dropped" message box. Now, click the button on the form to pop up a dialog box. Again, attempt to drag and drop a file onto the main window while the dialog box is open. Notice that the drop is allowed even though a modal dialog box is open. How can I prevent this from happening when the dialog is open?
The obvious answer is to temporarily set AllowDrop to false while opening the dialog box. The problem is that the main application is very large and so there are numerous places that open dialog boxes. It will be difficult to find every single place that opens a dialog and add this code. Plus, every developer here would need to know to perform this action every time they open a modal window; it is unlikely that everyone will remember. I am worried that this is not a very good solution.
Surely there is a more maintainable method of doing this that doesn't require adding code in every place that a dialog is opened?
using System;
using System.Windows.Forms;
using System.Drawing;
public class MyDialog : Form {
public MyDialog() {
Text = "MyDialog";
}
}
public class MainForm : Form {
public MainForm() {
Button btn = new Button();
btn.Location = new Point(0, 0);
btn.Text = "ShowDialog";
btn.Size = new Size(75, 23);
btn.Click += new EventHandler(GoToDialog);
this.AllowDrop = true;
this.Controls.Add(btn);
this.Text = "Drop Target";
this.DragDrop += new DragEventHandler(this.MyDragDrop);
this.DragEnter += new DragEventHandler(this.MyDragEnter);
}
private void MyDragDrop(object sender, DragEventArgs e) {
MessageBox.Show("dropped");
}
private void MyDragEnter(object sender, DragEventArgs e) {
e.Effect = DragDropEffects.Copy;
}
private void GoToDialog(object sender, EventArgs e) {
using (MyDialog ab = new MyDialog()) {
ab.ShowDialog(this);
}
}
}
static class Program {
[STAThread]
static void Main() {
Application.Run(new MainForm());
}
}
I'm not sure how things work in C#, so let me know if this answer is incorrect. In C++ MFC, the main window is disabled when a dialog is displayed. You can test to see if the main window is disabled and ignore the drop if so.
private void MyDragDrop(object sender, DragEventArgs e) {
if (CanFocus)
MessageBox.Show("dropped");
}
private void MyDragEnter(object sender, DragEventArgs e) {
if (CanFocus)
e.Effect = DragDropEffects.Copy;
else
e.Effect = DragDropEffects.None;
}
I have a folderBrowserDialog control and i have a button named click
i did like this way
private void click_Click(object sender, EventArgs e)
{
folderBrowserDialog1.ShowDialog();
}
If what you wish to accomplish is to automatically display a folder of your choice whenever the FolderBrowserDialog is shown, then you can use the following code:
private void click_Click(object sender, EventArgs e)
{
FolderBrowserDialog f = new FolderBrowserDialog();
f.Description = "Please browse to, and select a folder";
f.RootFolder = #"C:\Name Of Folder You Want Displayed\";
using(f)
{
if(f.ShowDialog() == DialogResult.OK)
{
// Do something when the user clicks OK or Open.
}
}
}
Or, you could simply add a FolderBrowserDialog to your Form from the Visual Studio ToolBox and click on the Properties tab, and then click the down arrow to the right-hand side of the 'Root Folder' option and select one of the listed folders from the drop-down menu.
Hope this helps.
You can use a custom build Folder Browser Dialog/Control for this. Try this: http://www.codeproject.com/KB/miscctrl/FileBrowser.aspx