Inherit from messagebox in c#

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Adam

    Inherit from messagebox in c#

    I am trying to inherit from MessageBox and i get error in
    compilation time.

    The code is:
    public class MyMessageBox : MessageBox
    {
    public static DialogResult Show(int errorCode)
    {
    return DialogResult.OK ;
    }
    }

    The error is:
    System.Windows. Forms.MessageBo x.MessageBox() is
    inaccessible due to its protection level

    I guess it because the constructor of MessageBox is privte.
    My question is, is there anyway to inherit from messagebox?

    Thanks,
    Adam
  • Jon Skeet

    #2
    Re: Inherit from messagebox in c#

    Adam <adama@elbit.co .il> wrote:[color=blue]
    > I am trying to inherit from MessageBox and i get error in
    > compilation time.
    >
    > The code is:
    > public class MyMessageBox : MessageBox
    > {
    > public static DialogResult Show(int errorCode)
    > {
    > return DialogResult.OK ;
    > }
    > }
    >
    > The error is:
    > System.Windows. Forms.MessageBo x.MessageBox() is
    > inaccessible due to its protection level
    >
    > I guess it because the constructor of MessageBox is privte.
    > My question is, is there anyway to inherit from messagebox?[/color]

    No. Unless a class has at least one protected or public (or internal if
    you're in the same assembly) constructor, you can't inherit from it (in
    C# at least).

    --
    Jon Skeet - <skeet@pobox.co m>
    Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

    If replying to the group, please do not mail me too

    Comment

    • Jon Skeet

      #3
      Re: Inherit from messagebox in c#

      Adam <adama@elbit.co .il> wrote:[color=blue]
      > I am trying to inherit from MessageBox and i get error in
      > compilation time.
      >
      > The code is:
      > public class MyMessageBox : MessageBox
      > {
      > public static DialogResult Show(int errorCode)
      > {
      > return DialogResult.OK ;
      > }
      > }
      >
      > The error is:
      > System.Windows. Forms.MessageBo x.MessageBox() is
      > inaccessible due to its protection level
      >
      > I guess it because the constructor of MessageBox is privte.
      > My question is, is there anyway to inherit from messagebox?[/color]

      No. Unless a class has at least one protected or public (or internal if
      you're in the same assembly) constructor, you can't inherit from it (in
      C# at least).

      --
      Jon Skeet - <skeet@pobox.co m>
      Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

      If replying to the group, please do not mail me too

      Comment

      • Willy Denoyette [MVP]

        #4
        Re: Inherit from messagebox in c#

        Adam wrote:
        || I am trying to inherit from MessageBox and i get error in
        || compilation time.
        ||
        || The code is:
        || public class MyMessageBox : MessageBox
        || {
        || public static DialogResult Show(int errorCode)
        || {
        || return DialogResult.OK ;
        || }
        || }
        ||
        || The error is:
        || System.Windows. Forms.MessageBo x.MessageBox() is
        || inaccessible due to its protection level
        ||
        || I guess it because the constructor of MessageBox is privte.
        || My question is, is there anyway to inherit from messagebox?
        ||
        || Thanks,
        || Adam

        No, the class has only a private constructor, so you can't derive from nor create an instance of the class.

        Willy.


        Comment

        • Willy Denoyette [MVP]

          #5
          Re: Inherit from messagebox in c#

          Adam wrote:
          || I am trying to inherit from MessageBox and i get error in
          || compilation time.
          ||
          || The code is:
          || public class MyMessageBox : MessageBox
          || {
          || public static DialogResult Show(int errorCode)
          || {
          || return DialogResult.OK ;
          || }
          || }
          ||
          || The error is:
          || System.Windows. Forms.MessageBo x.MessageBox() is
          || inaccessible due to its protection level
          ||
          || I guess it because the constructor of MessageBox is privte.
          || My question is, is there anyway to inherit from messagebox?
          ||
          || Thanks,
          || Adam

          No, the class has only a private constructor, so you can't derive from nor create an instance of the class.

          Willy.


          Comment

          Working...