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. C# win forms .net core, user control, array on a dialog.

C# win forms .net core, user control, array on a dialog.

Scheduled Pinned Locked Moved C#
csharpjavascriptasp-netdotnetcom
12 Posts 5 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.
  • J jkirkerx

    I made a user control to represent cardboard boxes, probably a bad idea. The idea is to be able to add a box, like if you have 3 boxes. I was thinking like in Angular, you can make a control array, so it was just natural for me to make a user control. I placed one on my dialog, and I'm just drawing a blank on how to handle this on the dialog. Haven't tried anything yet, but did look around and all the examples were for check boxes. I suppose if I can't make it work, I can re-purpose it to fill a list box, or to fill the box array in my model.

    If it ain't broke don't fix it Discover my world at jkirkerx.com

    B Offline
    B Offline
    BillWoodruff
    wrote on last edited by
    #3

    To assist you, we need to know more about what the "boxes" represent, how they are used, does the user interacts with them at run-time, etc. Do the "boxes": contain other Controls: if so, what are they ?

    «One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali

    U 1 Reply Last reply
    0
    • B BillWoodruff

      To assist you, we need to know more about what the "boxes" represent, how they are used, does the user interacts with them at run-time, etc. Do the "boxes": contain other Controls: if so, what are they ?

      «One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali

      U Offline
      U Offline
      User 13293914
      wrote on last edited by
      #4

      Thank You, yes, it is a real-time software that showing data (querying) whilst data are recorded, and user(s) can querying anytime they need. Values will be shown in textBoxes and chart controls. my database structure only contains double-precision, string, and int Fields. If My info is not enough tell me and i will add anything needed. Thank you again.

      OriginalGriffO 1 Reply Last reply
      0
      • U User 13293914

        Thank You, yes, it is a real-time software that showing data (querying) whilst data are recorded, and user(s) can querying anytime they need. Values will be shown in textBoxes and chart controls. my database structure only contains double-precision, string, and int Fields. If My info is not enough tell me and i will add anything needed. Thank you again.

        OriginalGriffO Offline
        OriginalGriffO Offline
        OriginalGriff
        wrote on last edited by
        #5

        No, what Bill is asking for is simpler: UserControl is a special class that allows you teh developer to create a displayable object that shows information to the user and accepts user input - exactly as a TextBox does. We need to know if the user interacts directly with them (and how if so), how they are used in your app - if you have created the correct object, in fact. If they are always "internal" to yoru app and are never visible to the user then a UserControl is the wrong choice - a simple class is better as all displayable controls bring a lot of necessary "baggage" with them that a class does not. If you are trying to show items on a form, then a UserControl is the way to go, but we need to know what you are trying to do with them from a user point of view before we can help you - remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with.

        "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

        "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
        "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

        J 1 Reply Last reply
        0
        • OriginalGriffO OriginalGriff

          No, what Bill is asking for is simpler: UserControl is a special class that allows you teh developer to create a displayable object that shows information to the user and accepts user input - exactly as a TextBox does. We need to know if the user interacts directly with them (and how if so), how they are used in your app - if you have created the correct object, in fact. If they are always "internal" to yoru app and are never visible to the user then a UserControl is the wrong choice - a simple class is better as all displayable controls bring a lot of necessary "baggage" with them that a class does not. If you are trying to show items on a form, then a UserControl is the way to go, but we need to know what you are trying to do with them from a user point of view before we can help you - remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with.

          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

          J Offline
          J Offline
          jkirkerx
          wrote on last edited by
          #6

          The boxes are literary, well represent card board boxes for shipping. In the user control, you select the item, enter unit cost, how many units, and ship label price. Every shipment has at least one box. You can add boxes, say if your shipment has 4 boxes to ship. So if you have 60 units to ship, and 15 units go in each box, you have 4 boxes.

          If it ain't broke don't fix it Discover my world at jkirkerx.com

          OriginalGriffO 1 Reply Last reply
          0
          • J jkirkerx

            The boxes are literary, well represent card board boxes for shipping. In the user control, you select the item, enter unit cost, how many units, and ship label price. Every shipment has at least one box. You can add boxes, say if your shipment has 4 boxes to ship. So if you have 60 units to ship, and 15 units go in each box, you have 4 boxes.

            If it ain't broke don't fix it Discover my world at jkirkerx.com

            OriginalGriffO Offline
            OriginalGriffO Offline
            OriginalGriff
            wrote on last edited by
            #7

            So are they pictures of boxes? Do I click on them? Or are they a list of contents plus "add / remove" buttons? Seriously, we only get exactly what you type to work with here!

            "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

            "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
            "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

            J 1 Reply Last reply
            0
            • OriginalGriffO OriginalGriff

              So are they pictures of boxes? Do I click on them? Or are they a list of contents plus "add / remove" buttons? Seriously, we only get exactly what you type to work with here!

              "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

              J Offline
              J Offline
              jkirkerx
              wrote on last edited by
              #8

              My Bad It's a rectangle, with 1 combo at the top, then 3 textboxes underneath. No add / remove buttons, they are at the top of container, outside the user control. I tried to draw a picture with text, didn't work out.

              If it ain't broke don't fix it Discover my world at jkirkerx.com

              OriginalGriffO 1 Reply Last reply
              0
              • J jkirkerx

                I made a user control to represent cardboard boxes, probably a bad idea. The idea is to be able to add a box, like if you have 3 boxes. I was thinking like in Angular, you can make a control array, so it was just natural for me to make a user control. I placed one on my dialog, and I'm just drawing a blank on how to handle this on the dialog. Haven't tried anything yet, but did look around and all the examples were for check boxes. I suppose if I can't make it work, I can re-purpose it to fill a list box, or to fill the box array in my model.

                If it ain't broke don't fix it Discover my world at jkirkerx.com

                J Offline
                J Offline
                jkirkerx
                wrote on last edited by
                #9

                So I deleted the control off the dialog box, and decided to create the control in code. This is where I got confused. I made a panel, set the sizes up static, and wrote some code, where I click on "ADD", and add the user control to the panel. I did figure out the direct injection part, injecting my inventory repository, and when adding the control the Item list populates. It's a start at least. Just need to calculate the next box location. I can relate to this, and will test it out and see how it goes before I abandon the idea. Maybe I should be using that Flow Panel control.

                private void Btn_Add_Click(object sender, EventArgs e)
                {
                var ucCount = panelItems.Controls.Count;
                var ucLocation = new Point(0, 0);

                var shipmentControl = new AmazonFBAShipmentControl(inventoryRepository);
                shipmentControl.Location = ucLocation;
                       
                panelItems.Controls.Add(shipmentControl);
                

                }

                If it ain't broke don't fix it Discover my world at jkirkerx.com

                1 Reply Last reply
                0
                • J jkirkerx

                  My Bad It's a rectangle, with 1 combo at the top, then 3 textboxes underneath. No add / remove buttons, they are at the top of container, outside the user control. I tried to draw a picture with text, didn't work out.

                  If it ain't broke don't fix it Discover my world at jkirkerx.com

                  OriginalGriffO Offline
                  OriginalGriffO Offline
                  OriginalGriff
                  wrote on last edited by
                  #10

                  Right - so it has to be a UserControl, and you need to have an "expanding" collection control to put them on. I'd probably start with a FlowLayoutPanel - but it depends on how you want to arrange them. Every time you click the button, it adds another item to it and flows them around to fit:

                      private void button1\_Click(object sender, EventArgs e)
                          {
                          Button b = new Button();
                          b.Text = $"Hello: {++buttonsCount}";
                          b.Click += MyAddedButton\_Click;
                          myFlowLayoutPanel.Controls.Add(b);
                          }
                      private int buttonsCount = 0;
                      private void MyAddedButton\_Click(object sender, EventArgs e)
                          {
                          Console.WriteLine((sender as Button)?.Text);
                          }
                  

                  "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

                  "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                  "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                  J 1 Reply Last reply
                  0
                  • OriginalGriffO OriginalGriff

                    Right - so it has to be a UserControl, and you need to have an "expanding" collection control to put them on. I'd probably start with a FlowLayoutPanel - but it depends on how you want to arrange them. Every time you click the button, it adds another item to it and flows them around to fit:

                        private void button1\_Click(object sender, EventArgs e)
                            {
                            Button b = new Button();
                            b.Text = $"Hello: {++buttonsCount}";
                            b.Click += MyAddedButton\_Click;
                            myFlowLayoutPanel.Controls.Add(b);
                            }
                        private int buttonsCount = 0;
                        private void MyAddedButton\_Click(object sender, EventArgs e)
                            {
                            Console.WriteLine((sender as Button)?.Text);
                            }
                    

                    "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

                    J Offline
                    J Offline
                    jkirkerx
                    wrote on last edited by
                    #11

                    Good call. I changed the panel to the flow layout panel, went top to bottom. This is really cool! This panel automatically positions my user control perfect and makes a scroll bar when needed. I'm in the process of wiring it all up now, so far so good. No different than passing data from a form to a dialog. You can't see me, but I have a huge smile on my face. :) And I know I choose the right path. I'm very happy with .Net Core Win Forms using direct injection, so far it's working great for me. I love using the app I made with this technology. Thanks Griff!

                    If it ain't broke don't fix it Discover my world at jkirkerx.com

                    OriginalGriffO 1 Reply Last reply
                    0
                    • J jkirkerx

                      Good call. I changed the panel to the flow layout panel, went top to bottom. This is really cool! This panel automatically positions my user control perfect and makes a scroll bar when needed. I'm in the process of wiring it all up now, so far so good. No different than passing data from a form to a dialog. You can't see me, but I have a huge smile on my face. :) And I know I choose the right path. I'm very happy with .Net Core Win Forms using direct injection, so far it's working great for me. I love using the app I made with this technology. Thanks Griff!

                      If it ain't broke don't fix it Discover my world at jkirkerx.com

                      OriginalGriffO Offline
                      OriginalGriffO Offline
                      OriginalGriff
                      wrote on last edited by
                      #12

                      You're welcome!

                      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

                      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                      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