Dialogresult for picturebox
Hi All,
the Button class is using, among other, the DialogResult Property, Which I use and it works great!
But...
know I whant to use DialogResult in combination with a PictureBox, which I use in severall cases as a button, to get rit of the
overload given by the button class.
I made a Custom Component PictureBox called "CPictureBox".
But know I have to implement the dialogresult into it.
How should this be done??
I know this is not an easy one..........
Regards,
Ger
Re: Dialogresult for picturebox
Hi All,
Came up with this:
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Test
{
public partial class CPictureBox : System.Windows.Forms.PictureBox
{
public DialogResult Dialogresult
{
get;
set;
}
}
}
is this correct...
regards,
Ger
Re: Dialogresult for picturebox
Hi All,
After some digging I came up with this;
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Test
{
public partial class CPictureBox : System.Windows.Forms.PictureBox
{
private DialogResult _DialogResult;
public DialogResult DialogResult
{
get
{
return _DialogResult;
}
set
{
_DialogResult = value;
}
}
}
}
It is not working 100%, the return value is allways "Cancel".
Other options are; OK, Retry, Abort etc.
So there is a glitch in the transport of the correct value.
Help me out!!..........please.
Regards,
Ger
Re: Dialogresult for picturebox
Why don't you zip up a complete sample project and post it here? Then folks can load your project, see what you are doing wrong and repost a corrected zip file.
1 Attachment(s)
Re: Dialogresult for picturebox
Hi All,
Here is the Zipper of a Sample project
Regards,
Ger
Re: Dialogresult for picturebox
You have a couple of issues with your code:
1) In form2, you aren't setting the dialogresult from each picture box back to the dialog result of Form2. If you had derived from a button instead of a picture box, this would be connected up automatically for you. No matter, just set them in the click handlers.
Code:
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void cPictureBox1_Click(object sender, EventArgs e)
{
DialogResult = cPictureBox1.DialogResult;
Close();
}
private void cPictureBox2_Click(object sender, EventArgs e)
{
DialogResult = cPictureBox2.DialogResult;
Close();
}
}
2) In the Form1 button handler, the logic for checking the dialogresult value from Form2 is wrong.
See how 'Yes' is displayed twice in the commented out code? Also, if 'Yes' is the dialog result, the error statement will also be displayed?
Code:
private void button1_Click(object sender, EventArgs e)
{
DialogResult dr = new DialogResult();
Form2 F2 = new Form2();
dr = F2.ShowDialog();
string msg;
switch(dr)
{
case DialogResult.Yes:
msg = "You Presses the Yes Custom Picture Box";
break;
case DialogResult.No:
msg = "You Presses the No Custom Picture Box";
break;
default:
msg = String.Format("Unknown DialogResult: {0}", dr);
break;
}
MessageBox.Show(msg);
//if (dr == DialogResult.Yes)
// MessageBox.Show("You Presses the Yes Custom Picture Box");
//if (dr == DialogResult.No)
// MessageBox.Show("You Presses the Yes Custom Picture Box");
//else
// MessageBox.Show("DialogResult Error......");
}
Re: Dialogresult for picturebox
hi Arjay,
Thanks for the reply!!
Now it is working like it should.
and so easy....
Now I want to go one step futher.
I want to make use of the TAB key, just like 'normal' buttons.
So I need OnLeave and OnEnter.
How can I place this in my CustomPictureBox. (need to derive from control I think)
and How do I fire them.
So let say if the 'button' has focus the Yes or No text will be underlined, something like that.
Regards,
Ger
Re: Dialogresult for picturebox
You'll be better off starting with a button, setting it's style to flat and then attaching an image.
Re: Dialogresult for picturebox
Hi Arjay,
Yep Button would be better, but it gives me a lot unwanted site efects.....
I will posts a zip of an example shortly.
regards,
Ger
Re: Dialogresult for picturebox
Quote:
Originally Posted by
TBBW
Yep Button would be better, but it gives me a lot unwanted site efects.....
Like what?
1 Attachment(s)
Re: Dialogresult for picturebox
hi Arjay,
here is the zipper of a buttonTester.
with the mentioned unwanted effects.
regards,
Ger