I am trying to get the background image fot the trackbar only. I used following snippet but the image is not visible.
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}[enter image description here][1]
private void trackBar1_Scroll(object sender, EventArgs e)
{
//this.trackBar1.
this.trackBar1.BackgroundImage =
Image.FromFile(#"C:\Users\310276521\Documents\Aftab\Untitled.jpg");
}
}
I want to implement this kind of layout:
try this
private void trackBar1_Scroll(object sender, EventArgs e)
{
//this.trackBar1.
this.trackBar1.BackgroundImage = Image.FromFile(#"C:\\Users\\310276521\\Documents\\Aftab\\Untitled.jpg");
}
Please make sure you are having the image in that location
Related
I have made a method including the code of pie chart and call that method everywhere i need to refresh the chart, but whenever i click on those buttons where i have called the method then the pie chart duplicates the value automatically. And also i have tried Refresh() and Update option too but it doesn't work.
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
chart();
}
private void chart()
{
chart1.Series["new"].Points.AddXY("Peter", "1000");
chart1.Series["new"].Points.AddXY("Julia", "1000");
}
private void button1_Click(object sender, EventArgs e)
{
chart();
}
}
If I've understood the problem correctly, I think you simply need to clear down the Series' Points collection.
For example:
private void chart()
{
chart1.Series["new"].Points.Clear();
chart1.Series["new"].Points.AddXY("Peter", "1000");
chart1.Series["new"].Points.AddXY("Julia", "1000");
}
Is this what you were looking to do?
I am having two forms (A and B). In form B there are many buttons having different background image. On clicking any of the button I want to change the background image of form A to the background image of the button which was clicked instantly as it is always open behind the form.
formA mai = new formA();
private void button1_Click(object sender, EventArgs e)
{
mai.BackgroundImage = button1.BackgroundImage;
}
This is the code I am using although it changes the background image it doesn't change instantly but if I will open and close the form the background image will be changed.
I don't need like that I need it to change instantly.
Add a field in formB to refer to the formA instance which you want to change its BackgroundImage; and initialize it when you call formB
formB's code-behind:
public partial class formB : Form
{
public formA owner;
public formB()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (owner != null)
owner.BackgroundImage = button1.BackgroundImage;
}
private void button2_Click(object sender, EventArgs e)
{
if (owner != null)
owner.BackgroundImage = button2.BackgroundImage;
}
private void button3_Click(object sender, EventArgs e)
{
if (owner != null)
owner.BackgroundImage = button3.BackgroundImage;
}
}
formA's code-behind:
public partial class formA : Form
{
public formA()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
formB b = new formB();
b.owner = this;
b.ShowDialog();
}
}
Add this.Refresh()
formA mai = new formA();
private void button1_Click(object sender, EventArgs e)
{
mai.BackgroundImage = button1.BackgroundImage;
mai.BringToFront();
mai.Refresh();
}
Call mai.Invalidate() after setting the new image.
I want to display the current page-name that's on my WebBrowser control on my Label, but when the Document.Title updates, my label disappears instead of showing the current website title. How can i fix this?
public partial class StreamViewer : Form
{
public StreamViewer()
{
InitializeComponent();
webBrowserViewer.DocumentTitleChanged += new EventHandler(webBrowserViewer_DocumentTitleChanged);
}
private void webBrowserViewer_DocumentTitleChanged(object sender, EventArgs e)
{
label2.Text = webBrowserViewer.DocumentTitle;
}
Use the DocumentTitleChanged event
public Form1()
{
InitializeComponent();
webBrowserViewer.DocumentTitleChanged += new EventHandler(webBrowserViewer_DocumentTitleChanged);
}
private void webBrowserViewer_DocumentTitleChanged(object sender, EventArgs e)
{
label2.Text = webBrowser1.DocumentTitle;
}
https://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.documenttitlechanged(v=vs.110).aspx
I have a windows custom control with a picturebox and a button on it's default panel. This windows custom control will be added to a windows form. There is another windows form called form2. when the user double clicks on the custom control, it should load form2. in designer when i double clicked the custom control on the form, it creates a load() event for that custom control. But i need double click event, how this can be done?
here is the graphical view of what happens
Here is code in the control
[DefaultEvent("DoubleClick")]
public partial class cntrlImageLoader : UserControl
{
public cntrlImageLoader()
{
InitializeComponent();
}
private void btnBrowse_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.InitialDirectory = Environment.SpecialFolder.MyPictures.ToString();
if (ofd.ShowDialog() == DialogResult.OK)
{
pbImage.Image = Image.FromFile(ofd.FileName);
}
}
private void pbImage_Click(object sender, EventArgs e)
{
this.cntrlImageLoader_DoubleClick(pbImage, e);
}
private void cntrlImageLoader_Load(object sender, EventArgs e)
{
}
private void cntrlImageLoader_DoubleClick(object sender, EventArgs e)
{
}
}
Here is the calling code on form1
private void cntrImLdrFront_DoubleClick(object sender, EventArgs e)
{
//this.cntrImLdrFront.pbImage.DoubleClick += new EventHandler(pbImage_DoubleClick);
}
FrmImageViewer f; // this is form2
private void pbImage_DoubleClick(object sender, EventArgs e)
{
f= new FrmImageViewer();
f.MdiParent = this.MdiParent;
f.Show();
}
Assign the attribute [DefaultEvent("DoubleClick")] at the class declaration.
[DefaultEvent("DoubleClick")]
public partial class MyControl : UserControl
{
}
This will creates event which you have set by default on double click of control at design time where you have placed your user control.
EDITED:
[DefaultEvent("LoadPicture")]
public partial class cntrlImageLoader : UserControl
{
public delegate void LoadPictureEventHandler(object sender, LoadPictureEventArgs e);
public event LoadPictureEventHandler LoadPicture;
private void pbImage_DoubleClick(object sender, EventArgs e)
{
if (LoadPicture != null)
{
LoadPictureEventArgs ev = new LoadPictureEventArgs();
LoadPicture(this, ev);
if (ev.Picture != null)
{
pbImage.Image = ev.Picture;
}
}
}
}
Create another class and give that class name to LoadPictureEventArgs
public class LoadPictureEventArgs : EventArgs
{
public Image Picture {get; set;}
public LoadPictureEventArgs(Image _picture)
{
Picture = _picture
}
public LoadPictureEventArgs()
: base()
{
}
}
HOW TO USE IT?
//FORM1
private void cntrImLdrFron_LoadPicture(object sender, LoadPictureEventArgs e)
{
Image img = null;
//LOAD YOUR IMAGE HERE
e.Picture = img;
}
I have a little project in C#, (Windows Forms Application). I have on the form 77 PictureBoxes (pictureBox1, pictureBox2, pictureBox3, ...) and I want to control them but from a new class (Access.cs), by declaring a new one picturebox in the class to control all the pictures.
Because it would be too long if I pass through each pictureBox and add a click method and Copy + Paste the code and change the pictureBox number each time.
I've set the pictures as public and tried the following code:
Access.cs:
using System.Windows.Forms;
public class Access
{
PictureBox picBox = new PictureBox();
public void PictureClicked()
{
picBox.Image = Properties.Resources.apple;
}
}
Form1.cs:
private void pictureBox1_Click(object sender, EventArgs e)
{
Access ac = new Access();
ac.PictureClicked();
}
but the code didn't work!!
I dont really get what you want to do but you could try to send the object to your Access class:
private void pictureBox1_Click(object sender, EventArgs e)
{
Access ac = new Access();
ac.PictureClicked(sender);
}
public void PictureClicked(Object Sender)
{
picBox = (PictureBox)Sender;
picBox.Image = Properties.Resources.apple;
}
Access.Cs
public void pictureBox1_Click(object sender, EventArgs e)
{
PictureBox pi = (PictureBox)sender;
pi.Image = Properties.Resources.alert__2_;
}
Form1.Cs
private void pictureBox2_Click(object sender, EventArgs e)
{
Form1 c =new Form1();
c.pictureBox1_Click(sender, e);
}
Here pictureBox2_Click this event for all picturebox