Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Control visibility Problem in Inheriting WinForm!

Control visibility Problem in Inheriting WinForm!

Scheduled Pinned Locked Moved C#
helptutorialquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    majidbhutta
    wrote on last edited by
    #1

    Hi Dears! I need ur help to tackle the following scenario. I have total two win forms. F1,F2 F1 contains control,Timer,DateTimePicker ,Some text lable and A pictureBox, all are private. F2 inherits F1 ( F2:F1) when i call show methed for F2 with its instance all the controls of form F1 are visible on F2 hat i want to keep some of the controls invisble(not inherted and not visble) in inherited form F2. For Example i want the pictureBox control in F1 to be (public/private)static and not inhertable ,non visble on form F2. How to do this? Thnx in Advance!

    S 1 Reply Last reply
    0
    • M majidbhutta

      Hi Dears! I need ur help to tackle the following scenario. I have total two win forms. F1,F2 F1 contains control,Timer,DateTimePicker ,Some text lable and A pictureBox, all are private. F2 inherits F1 ( F2:F1) when i call show methed for F2 with its instance all the controls of form F1 are visible on F2 hat i want to keep some of the controls invisble(not inherted and not visble) in inherited form F2. For Example i want the pictureBox control in F1 to be (public/private)static and not inhertable ,non visble on form F2. How to do this? Thnx in Advance!

      S Offline
      S Offline
      Stanciu Vlad
      wrote on last edited by
      #2

      When you inherit a class all your base private members ar hidden. You can not inherit only certain memberber... Here are some possible resolutions for your problem : 1) make a base constuctor that allows you to specify the hiding of certain controls. Let's say you have a form (F1) with a button. The form which inherits F1 can call a base constuctor to specify this :

      // The base class
      public class F1 : ... {
      ...
      System.Windows.Forms.Button button1 = new System.Windows.Form.Button();
      ...
      // Here is your standar .ctor
      public F1() {
      ...
      // Initialize the form in what ever wy you desire
      ...
      }
      // Here is the .ctor that hides the button
      public F1(bool hideButton) : this() {
      button1.Visible = hideButton;
      }
      ...
      }

      // The derived class
      public class F2 : F1 {
      ...
      public F2 : base(true) {
      // initialize the form normaly
      }
      ...
      }

      1. Build in the base class an accesor that let's you change the state of certain controls (ie. the visible property of a button as in the previous example)

      // The base class
      public class F1 : ... {
      ...
      System.Windows.Forms.Button button1 = new System.Windows.Form.Button();
      ...
      public SetButtonVisibility {
      get {
      return button1.Visible;
      }
      set {
      button1.Visile = value;
      }
      }
      // Here is your standar .ctor
      public F1() {
      ...
      // Initialize the form in what ever wy you desire
      ...
      }
      ...
      }

      // The derived class
      public class F2 : F1 {
      ...
      public F2 : base(true) {
      SetButtonVisibility = false; // same as base.SetButtonVisibility = false;
      // initialize the form normaly
      }
      ...
      }

      I hope you understand...because is a rough world out there...

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups