Dialogresult for picturebox
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11

Thread: Dialogresult for picturebox

  1. #1
    Join Date
    Oct 2009
    Location
    Holland
    Posts
    198

    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

  2. #2
    Join Date
    Oct 2009
    Location
    Holland
    Posts
    198

    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

  3. #3
    Join Date
    Oct 2009
    Location
    Holland
    Posts
    198

    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

  4. #4
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,359

    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.

  5. #5
    Join Date
    Oct 2009
    Location
    Holland
    Posts
    198

    Re: Dialogresult for picturebox

    Hi All,

    Here is the Zipper of a Sample project

    Regards,

    Ger
    Attached Files Attached Files

  6. #6
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,359

    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......");
            }

  7. #7
    Join Date
    Oct 2009
    Location
    Holland
    Posts
    198

    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

  8. #8
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,359

    Re: Dialogresult for picturebox

    You'll be better off starting with a button, setting it's style to flat and then attaching an image.

  9. #9
    Join Date
    Oct 2009
    Location
    Holland
    Posts
    198

    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

  10. #10
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,359

    Re: Dialogresult for picturebox

    Quote Originally Posted by TBBW View Post
    Yep Button would be better, but it gives me a lot unwanted site efects.....
    Like what?

  11. #11
    Join Date
    Oct 2009
    Location
    Holland
    Posts
    198

    Re: Dialogresult for picturebox

    hi Arjay,

    here is the zipper of a buttonTester.
    with the mentioned unwanted effects.

    regards,

    Ger
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center