I have C# code linked to an xaml file that builds a GUI. In the GUI, when I click on an option, the photo appears, as I want. However, I can't figure out how to make it so the user has the option to close the photo. Here's my C# code:
public void help_click(object sender, RoutedEventArgs e)
{
Image img;
img = new Image();
Uri diagram = new Uri(#"pack://application:,,,/PTDGUI;component/Content/Icons/controlmap.png", UriKind.RelativeOrAbsolute);
img.Source = new BitmapImage(diagram);
canvasSpace.Children.Add(img);
}
Image is not based on Control. You may require to customize for this behavior by either writing custom control or trapping any other control events to close this image.
This discsussion(stackoverflow) explains both the options I've mentioned, should help in understand and implementing what you rquired.
you can use the same help button for both, initially button will display "Help", When user clicks help, load the image and change the button text to "Close" and toggle it back to "Help" when users clicks again.
if(button.Text ="Help")
{
---load image
button.Text = "Close";
}
else
{
--Clear image
button.Text ="Help"
}
you may also use bool flag instead of checking text.
Related
How do you use a button to send an image within the same page to another page in the application via the button click event?
In the method that is called on the button click, I'd use the application properties to store your image. Something like this (you will want to put a data type on your image):
Application.Current.Properties.Add("myImage", System.Windows.Media.Imaging.BitmapImage myBmp);
Window newWindow = new Window();
newWindow.Show();
Then on the window that opens, grab the image from the app properties like this (note that you'll want to cast your image as they image type you want):
transferredImage = (MYIMAGETYPE)Application.Current.Properties["myImage"];
var brush = new ImageBrush();
if (image != null)
{
brush.ImageSource = image;
btnCustomerPhoto.Background = brush;
}
Application.Current.Properties.Clear();
Of course, you don't have to clear the current properties if you don't want to, but I do to ensure I don't have anything sticking around I don't want.
There are other ways to do this but the application properties are easy to use and then get rid of.
I would like to improve my application's interface. Is it possible to add something like this(refer to image below)?:
When you click the name or move the cursor to the name, a pop up box will appear with user's main info. If possible, can you teach me the appropriate tools to use. I don't mind if it is basic tools, so i can make a little similar to the image.
BTW, i'm using visual studio 2013.
Here is an (absolutely minimal) example of a pop-up Panel that takes care of the showing and hiding:
Panel popPanel = new Panel();
private void linkLabel1_MouseEnter(object sender, EventArgs e)
{
popPanel.Parent = linkLabel1.Parent;
popPanel.Location = new Point(linkLabel1.Left - 20, linkLabel1.Top + 10);
//popPanel.displayData(someDataClassFromSender);
popPanel.Show();
popPanel.MouseLeave += (ss, ee) => { popPanel.Hide(); };
}
For the layout and display of the info on the Panel (or some other control) you should create a class PopUpPanel and give it a method to load the data it shall display..
If it is a web application go check out http://bootsnipp.com/snippets/featured/fancy-navbar-login-sign-in-form
Just change the event from click to hover.
And get youserlf a copy of bootstrap http://getbootstrap.com/
How can I change and save the back color in a C# Windows Application so that when I
close the application and run the program again the new color will be the
back color default?
You can get that going with very little effort. Select the form in the designer, in the Properties window open the ApplicationSettings node. Select (PropertyBinding) and click the button. Select BackColor in the popup dialog. Click the dropdown arrow and click New. Set the name to, say, "FormBackColor".
The only other thing you need is an option to let the user pick another color. Very easy to do with the ColorDialog class:
private void OptionChangeColor_Click(object sender, EventArgs e) {
using (var dlg = new ColorDialog()) {
if (dlg.ShowDialog() == DialogResult.OK) {
this.BackColor = Properties.Settings.Default.FormBackColor = dlg.Color;
Properties.Settings.Default.Save();
}
}
}
You'll need to save the new color in some file that you load on startup and apply as the background color.
Or use a user setting like this.
You could do something simple like File.WriteAllText("bg.txt", this.BackColor.ToString()); and when the app loads do this.BackColor = Color.FromName(File.ReadAllText("bg.txt"));
Of course storing this color in Isolated Storage or in the registry might be better. But you get the idea...
Some time ago there was thread about best practices to do that here on stackoverflow. Please take look: Best practice to save application settings in a Windows Forms Application
im trying to work with the menustrip and i have the helpToolStripMenuItem_Click may someone help me the code on how to put the documentation i.e if i click help a new window show appear with documentation like this picture i capture from a vlc help button
any ideas this is my empty code
private void helpToolStripMenuItem_Click(object sender, EventArgs e)
{
}
Make form (for example with name frm_Help) with RichTextBox and Button
In Richtextbox add all text (read this Richtextbox)
In button event click add
{
Close();
}
Somewhere where you want to show this form add
{
frm_Help frm=new frm_Help;
frm.ShowDialog();
}
To get the same result as in the image you posted, you need to create a new form, put a WebBrowser control to it and load the HTML page with the documentation to this control in the form's initialization code:
public HelpForm()
{
InitializeComponent();
string text = System.IO.File.ReadAllText(#"Docs\readme.html");
webBrowser1.DocumentText = text;
}
Here, the code reads HTML from the readme.html file located in the Docs subfolder of the folder where the EXE file is located.
You should create new form, containing all the text you want in it and in helpToolStripMenuItem_Click you should create new instance of that form and show it (as a dialog maybe)
Create a new form or add AboutBox and add RichTextbox control.
I have a save as image feature for charts in my application. The chart control is a custom user control with custom logic in them. It also has some scaling based on size, zoom etc. However, while saving them as an image I would like to give the user the option to set the size of the image (eg: 800x600 px # 300 DPI).
To do this I have created a Form with textboxes/checkboxes etc for various settings for image. One of these TextBoxes is for the file name. The file name textbox is readonly and is accompanied with a browse button which shows a SaveFileDialog when clicked.
The user clicks "Save As Image" in the main form's menu. I show the ImageExportDialog using the code below:
using(ImageExportDialog dlg = new ImageExportDialog())
{
if(dlg.ShowDialog() == DialogResult.OK)
{
//get the settings selected by the user and generate the image
}
}
In the ImageExportDialog, the user clicks on the browse button and the SaveFileDialog is shown as follows:
using(SaveFileDialog dlg = new SaveFileDialog())
{
if(dlg.ShowDialog() == DialogResult.OK)
{
txtFileName.Text = dlg.FileName;
}
}
Now the problem is, when the user clicks on "Save" button in the SaveFileDialog, as expected the txtFileName.Text is set, but the parent custom dialog also seems to return from the ShowDialog method and the DialogResult is the same as the one for SaveFileDialog! The control then goes on to the "get the settings selected by the user and generate the image" part of the code above.
Not really sure what I am doing wrong here!
Arghhh!!!
Found out the issue myself. I had copy-pasted the OK button of the ImageExportDialog to create the Browse button for the SaveFileDialog.
Guess what, the Browse button had it's DialogResult property set to "OK"! Changing it to "None" solved the issue.