Form Objects in Arrays

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Samishii23
    New Member
    • Sep 2009
    • 246

    #16
    ***
    After studying the auto generated code of the Designer. I got past my own problem. For now...
    ***
    Last edited by Samishii23; Sep 22 '09, 04:17 PM. Reason: Fixed

    Comment

    • tlhintoq
      Recognized Expert Specialist
      • Mar 2008
      • 3532

      #17
      The string reference was only from the MSDN reference. I wasn't planing on using strings here
      If you want help with your code that isn't working it would help if you would supply your code that isn't working.

      Saying your code doesn't work, the supply bits of code from MSDN doesn't help anyone here to help you.

      Comment

      • GaryTexmo
        Recognized Expert Top Contributor
        • Jul 2009
        • 1501

        #18
        Well, the MSDN example is using a list of strings, you're using a list of images, that's the difference :)

        Since Image is an abstract class (I think... a base type at any rate), you can't instantiate a new object of type Image. But you can put Bitmaps in there, which is just an Image storage class.

        Instead of...

        Code:
        List<Image> imageList = new List<Image>();
        imageList.Add("image.jpg");
        ... try ...

        Code:
        List<Image> imageList = new List<Image>();
        imageList.Add(new Bitmap("image.jpg"));
        As tlhintoq mentioned though, this will eat up your memory. There are alternatives, but see if you can get it working for now, and we can talk optimizations after.

        Comment

        • tlhintoq
          Recognized Expert Specialist
          • Mar 2008
          • 3532

          #19
          Originally posted by Samishii23
          Off subject since the problem just came up for me...

          I have a win app, which is pretty much brand new. In the Main() function we make a panel object named "FPan", and Main() can do with it whatever it wants...
          Have a picturebox which were generated from the Main() function.

          But I have an Event Function in the same class. A mouse hover event catcher "PBImg_MouseHov er(object sender, System.EventArg s e)"
          In this function I want to play with the properties of the FPan from the Main() function. Compiler says FPan isn't an object... What do I do.
          Don't muddy up the thread with two completely different problems which even you say "is completely off topic." You need to start a new thread with the new question/issue.

          Comment

          • Samishii23
            New Member
            • Sep 2009
            • 246

            #20
            I'm going to start fresh with new project since the List<> works in a fresh project and not the original one.

            Feel free to close this thread.
            Thanks for the help of you both. I'll probally see you around later with a more Q's in another thread with more details of the problems and problematic code.
            Sorry to be such a n00b tlhintoq.

            Comment

            • tlhintoq
              Recognized Expert Specialist
              • Mar 2008
              • 3532

              #21
              Code:
              List<Image> imageList = new List<Image>();
              imageList.Add(new Bitmap("image.jpg"));
              Just plain bad. First of all "image.jpg" isn't in any way a valid path to a file. All it can possibly do is fail. If it were a valid path, Bitmap(string Path) keeps a link open to the hard drive file until the application closes. This will cause all kinds of issues if you try to move/rename/delete the file.

              Secondly it doesn't account for any time of error compensation. If the file is damage then this entire function breaks.

              You should have a dedicated image loading method that can recover from problems, If that method returns an image then you can load it into your list.

              Comment

              • tlhintoq
                Recognized Expert Specialist
                • Mar 2008
                • 3532

                #22
                Originally posted by Samishii23
                I'm going to start fresh with new project since the List<> works in a fresh project and not the original one.

                Feel free to close this thread.
                Thanks for the help of you both. I'll probally see you around later with a more Q's in another thread with more details of the problems and problematic code.
                Sorry to be such a n00b tlhintoq.
                We are all noobies helping each other out. That's why it is called a 'community'. Don't apologize.

                If you choose to start a new project that's up to you. If you want to actually *understand* why it doesn't work in your current project, feel free to post the actual code that's failing and we will see if we can find a reason.

                Comment

                • Samishii23
                  New Member
                  • Sep 2009
                  • 246

                  #23
                  Good point... Lol. Here goes nothing. One reason I would like to start over, is all that is from when I first started learning the language, and it seems to me is over-bloated, and repeative... Might just be me.

                  Also all the objects in the Form were generated using the Designer...

                  Main.cs
                  Code:
                  using System;
                  using System.Collections.Generic;
                  using System.ComponentModel;
                  using System.Drawing;
                  using System.Drawing.Imaging;
                  using System.Windows.Forms;
                  using TCImg = TalentCalc.Properties.Resources;
                  using DLLClass;
                  
                  namespace TalentCalc
                  {
                      public partial class TalentCalc : Form
                      {
                          private void TalentCalc_Load(object sender, EventArgs e)
                          {
                              load_loadicons();
                              load_hideall();
                              //TalentCalc.ActiveForm.Icon = new Icon(ClassDLL.GetProjectIcon());
                  
                              // PictureBox "FrontDisplay" Will be the "Opaque" BAckset for the icons.
                              // Need to re-size to (895, 583) and probally will need to Re-Draw
                          }
                          List<PictureBox> L_IconBox = new List<PictureBox>();
                  
                  
                  
                  
                          #region Probally won't work
                          string[] Tree1Icons = new string[] {
                              "icon_1_1_1","icon_1_1_2","icon_1_1_3","icon_1_1_4",
                              "icon_1_2_1","icon_1_2_2","icon_1_2_3","icon_1_2_4",
                              "icon_1_3_1","icon_1_3_2","icon_1_3_3","icon_1_3_4",
                              "icon_1_4_1","icon_1_4_2","icon_1_4_3","icon_1_4_4",
                              "icon_1_5_1","icon_1_5_2","icon_1_5_3","icon_1_5_4",
                              "icon_1_6_1","icon_1_6_2","icon_1_6_3","icon_1_6_4",
                              "icon_1_7_1","icon_1_7_2","icon_1_7_3","icon_1_7_4",
                              "icon_1_8_1","icon_1_8_2","icon_1_8_3","icon_1_8_4",
                              "icon_1_9_1","icon_1_9_2","icon_1_9_3","icon_1_9_4",
                              "icon_1_10_1","icon_1_10_2","icon_1_10_3","icon_1_10_4",
                              "icon_1_11_1","icon_1_11_2","icon_1_11_3","icon_1_11_4"
                              };
                          string[] Tree2Icons = new string[] {
                              "icon_2_1_1","icon_2_1_2","icon_2_1_3","icon_2_1_4",
                              "icon_2_2_1","icon_2_2_2","icon_2_2_3","icon_2_2_4",
                              "icon_2_3_1","icon_2_3_2","icon_2_3_3","icon_2_3_4",
                              "icon_2_4_1","icon_2_4_2","icon_2_4_3","icon_2_4_4",
                              "icon_2_5_1","icon_2_5_2","icon_2_5_3","icon_2_5_4",
                              "icon_2_6_1","icon_2_6_2","icon_2_6_3","icon_2_6_4",
                              "icon_2_7_1","icon_2_7_2","icon_2_7_3","icon_2_7_4",
                              "icon_2_8_1","icon_2_8_2","icon_2_8_3","icon_2_8_4",
                              "icon_2_9_1","icon_2_9_2","icon_2_9_3","icon_2_9_4",
                              "icon_2_10_1","icon_2_10_2","icon_2_10_3","icon_2_10_4",
                              "icon_2_11_1","icon_2_11_2","icon_2_11_3","icon_2_11_4"
                          };
                          #endregion
                  
                          System.Windows.Forms.PictureBox[] pBox = new PictureBox[1];
                          
                  
                          public TalentCalc()
                          {
                              InitializeComponent();
                          }
                  
                          #region Intialize Druid Trees
                          
                          #endregion
                  
                          public void load_loadicons()
                          {
                              FrontIcon01.Image = ClassDLL.GetClassIcon(0);
                              FrontIcon02.Image = ClassDLL.GetClassIcon(1);
                              FrontIcon03.Image = ClassDLL.GetClassIcon(2);
                              FrontIcon04.Image = ClassDLL.GetClassIcon(3);
                              FrontIcon05.Image = ClassDLL.GetClassIcon(4);
                              FrontIcon06.Image = ClassDLL.GetClassIcon(5);
                              FrontIcon07.Image = ClassDLL.GetClassIcon(6);
                              FrontIcon08.Image = ClassDLL.GetClassIcon(7);
                              FrontIcon09.Image = ClassDLL.GetClassIcon(8);
                              FrontIcon10.Image = ClassDLL.GetClassIcon(9);
                  
                              classicon1.Image = ClassDLL.GetClassIcon(0);
                              classicon2.Image = ClassDLL.GetClassIcon(1);
                              classicon3.Image = ClassDLL.GetClassIcon(2);
                              classicon4.Image = ClassDLL.GetClassIcon(3);
                              classicon5.Image = ClassDLL.GetClassIcon(4);
                              classicon6.Image = ClassDLL.GetClassIcon(5);
                              classicon7.Image = ClassDLL.GetClassIcon(6);
                              classicon8.Image = ClassDLL.GetClassIcon(7);
                              classicon9.Image = ClassDLL.GetClassIcon(8);
                              classicon10.Image = ClassDLL.GetClassIcon(9);
                  
                          }
                          public void load_hideall()
                          {
                              tree1_bg.Visible = false;
                              icon_1_1_1.Visible = false; icon_1_1_2.Visible = false; icon_1_1_3.Visible = false; icon_1_1_4.Visible = false;
                              icon_1_2_1.Visible = false; icon_1_2_2.Visible = false; icon_1_2_3.Visible = false; icon_1_2_4.Visible = false;
                              icon_1_3_1.Visible = false; icon_1_3_2.Visible = false; icon_1_3_3.Visible = false; icon_1_3_4.Visible = false;
                              icon_1_4_1.Visible = false; icon_1_4_2.Visible = false; icon_1_4_3.Visible = false; icon_1_4_4.Visible = false;
                              icon_1_5_1.Visible = false; icon_1_5_2.Visible = false; icon_1_5_3.Visible = false; icon_1_5_4.Visible = false;
                              icon_1_6_1.Visible = false; icon_1_6_2.Visible = false; icon_1_6_3.Visible = false; icon_1_6_4.Visible = false;
                              icon_1_7_1.Visible = false; icon_1_7_2.Visible = false; icon_1_7_3.Visible = false; icon_1_7_4.Visible = false;
                              icon_1_8_1.Visible = false; icon_1_8_2.Visible = false; icon_1_8_3.Visible = false; icon_1_8_4.Visible = false;
                              icon_1_9_1.Visible = false; icon_1_9_2.Visible = false; icon_1_9_3.Visible = false; icon_1_9_4.Visible = false;
                              icon_1_10_1.Visible = false; icon_1_10_2.Visible = false; icon_1_10_3.Visible = false; icon_1_10_4.Visible = false;
                              icon_1_11_2.Visible = false; icon_1_11_3.Visible = false; icon_1_11_4.Visible = false; icon_1_11_1.Visible = false;
                  
                              icontxt_1_1_1.Visible = false; icontxt_1_1_2.Visible = false; icontxt_1_1_3.Visible = false; icontxt_1_1_4.Visible = false;
                              icontxt_1_2_1.Visible = false; icontxt_1_2_2.Visible = false; icontxt_1_2_3.Visible = false; icontxt_1_2_4.Visible = false;
                              icontxt_1_3_1.Visible = false; icontxt_1_3_2.Visible = false; icontxt_1_3_3.Visible = false; icontxt_1_3_4.Visible = false;
                              icontxt_1_4_1.Visible = false; icontxt_1_4_2.Visible = false; icontxt_1_4_3.Visible = false; icontxt_1_4_4.Visible = false;
                              icontxt_1_5_1.Visible = false; icontxt_1_5_2.Visible = false; icontxt_1_5_3.Visible = false; icontxt_1_5_4.Visible = false;
                              icontxt_1_6_1.Visible = false; icontxt_1_6_2.Visible = false; icontxt_1_6_3.Visible = false; icontxt_1_6_4.Visible = false;
                              icontxt_1_7_1.Visible = false; icontxt_1_7_2.Visible = false; icontxt_1_7_3.Visible = false; icontxt_1_7_4.Visible = false;
                              icontxt_1_8_1.Visible = false; icontxt_1_8_2.Visible = false; icontxt_1_8_3.Visible = false; icontxt_1_8_4.Visible = false;
                              icontxt_1_9_1.Visible = false; icontxt_1_9_2.Visible = false; icontxt_1_9_3.Visible = false; icontxt_1_9_4.Visible = false;
                              icontxt_1_10_1.Visible = false; icontxt_1_10_2.Visible = false; icontxt_1_10_3.Visible = false; icontxt_1_10_4.Visible = false;
                              icontxt_1_11_1.Visible = false; icontxt_1_11_2.Visible = false; icontxt_1_11_3.Visible = false; icontxt_1_11_4.Visible = false;
                  
                              tree2_bg.Visible = false;
                              icon_2_1_1.Visible = false; icon_2_1_2.Visible = false; icon_2_1_3.Visible = false; icon_2_1_4.Visible = false;
                              icon_2_2_1.Visible = false; icon_2_2_2.Visible = false; icon_2_2_3.Visible = false; icon_2_2_4.Visible = false;
                              icon_2_3_1.Visible = false; icon_2_3_2.Visible = false; icon_2_3_3.Visible = false; icon_2_3_4.Visible = false;
                              icon_2_4_1.Visible = false; icon_2_4_2.Visible = false; icon_2_4_3.Visible = false; icon_2_4_4.Visible = false;
                              icon_2_5_1.Visible = false; icon_2_5_2.Visible = false; icon_2_5_3.Visible = false; icon_2_5_4.Visible = false;
                              icon_2_6_1.Visible = false; icon_2_6_2.Visible = false; icon_2_6_3.Visible = false; icon_2_6_4.Visible = false;
                              icon_2_7_1.Visible = false; icon_2_7_2.Visible = false; icon_2_7_3.Visible = false; icon_2_7_4.Visible = false;
                              icon_2_8_1.Visible = false; icon_2_8_2.Visible = false; icon_2_8_3.Visible = false; icon_2_8_4.Visible = false;
                              icon_2_9_1.Visible = false; icon_2_9_2.Visible = false; icon_2_9_3.Visible = false; icon_2_9_4.Visible = false;
                              icon_2_10_1.Visible = false; icon_2_10_2.Visible = false; icon_2_10_3.Visible = false; icon_2_10_4.Visible = false;
                              icon_2_11_2.Visible = false; icon_2_11_3.Visible = false; icon_2_11_4.Visible = false; icon_2_11_1.Visible = false;
                  
                              icontxt_2_1_1.Visible = false; icontxt_2_1_2.Visible = false; icontxt_2_1_3.Visible = false; icontxt_2_1_4.Visible = false;
                              icontxt_2_2_1.Visible = false; icontxt_2_2_2.Visible = false; icontxt_2_2_3.Visible = false; icontxt_2_2_4.Visible = false;
                              icontxt_2_3_1.Visible = false; icontxt_2_3_2.Visible = false; icontxt_2_3_3.Visible = false; icontxt_2_3_4.Visible = false;
                              icontxt_2_4_1.Visible = false; icontxt_2_4_2.Visible = false; icontxt_2_4_3.Visible = false; icontxt_2_4_4.Visible = false;
                              icontxt_2_5_1.Visible = false; icontxt_2_5_2.Visible = false; icontxt_2_5_3.Visible = false; icontxt_2_5_4.Visible = false;
                              icontxt_2_6_1.Visible = false; icontxt_2_6_2.Visible = false; icontxt_2_6_3.Visible = false; icontxt_2_6_4.Visible = false;
                              icontxt_2_7_1.Visible = false; icontxt_2_7_2.Visible = false; icontxt_2_7_3.Visible = false; icontxt_2_7_4.Visible = false;
                              icontxt_2_8_1.Visible = false; icontxt_2_8_2.Visible = false; icontxt_2_8_3.Visible = false; icontxt_2_8_4.Visible = false;
                              icontxt_2_9_1.Visible = false; icontxt_2_9_2.Visible = false; icontxt_2_9_3.Visible = false; icontxt_2_9_4.Visible = false;
                              icontxt_2_10_1.Visible = false; icontxt_2_10_2.Visible = false; icontxt_2_10_3.Visible = false; icontxt_2_10_4.Visible = false;
                              icontxt_2_11_1.Visible = false; icontxt_2_11_2.Visible = false; icontxt_2_11_3.Visible = false; icontxt_2_11_4.Visible = false;
                  
                              tree3_bg.Visible = false;
                              icon_3_1_1.Visible = false; icon_3_1_2.Visible = false; icon_3_1_3.Visible = false; icon_3_1_4.Visible = false;
                              icon_3_2_1.Visible = false; icon_3_2_2.Visible = false; icon_3_2_3.Visible = false; icon_3_2_4.Visible = false;
                              icon_3_3_1.Visible = false; icon_3_3_2.Visible = false; icon_3_3_3.Visible = false; icon_3_3_4.Visible = false;
                              icon_3_4_1.Visible = false; icon_3_4_2.Visible = false; icon_3_4_3.Visible = false; icon_3_4_4.Visible = false;
                              icon_3_5_1.Visible = false; icon_3_5_2.Visible = false; icon_3_5_3.Visible = false; icon_3_5_4.Visible = false;
                              icon_3_6_1.Visible = false; icon_3_6_2.Visible = false; icon_3_6_3.Visible = false; icon_3_6_4.Visible = false;
                              icon_3_7_1.Visible = false; icon_3_7_2.Visible = false; icon_3_7_3.Visible = false; icon_3_7_4.Visible = false;
                              icon_3_8_1.Visible = false; icon_3_8_2.Visible = false; icon_3_8_3.Visible = false; icon_3_8_4.Visible = false;
                              icon_3_9_1.Visible = false; icon_3_9_2.Visible = false; icon_3_9_3.Visible = false; icon_3_9_4.Visible = false;
                              icon_3_10_1.Visible = false; icon_3_10_2.Visible = false; icon_3_10_3.Visible = false; icon_3_10_4.Visible = false;
                              icon_3_11_2.Visible = false; icon_3_11_3.Visible = false; icon_3_11_4.Visible = false; icon_3_11_1.Visible = false;
                  
                              icontxt_3_1_1.Visible = false; icontxt_3_1_2.Visible = false; icontxt_3_1_3.Visible = false; icontxt_3_1_4.Visible = false;
                              icontxt_3_2_1.Visible = false; icontxt_3_2_2.Visible = false; icontxt_3_2_3.Visible = false; icontxt_3_2_4.Visible = false;
                              icontxt_3_3_1.Visible = false; icontxt_3_3_2.Visible = false; icontxt_3_3_3.Visible = false; icontxt_3_3_4.Visible = false;
                              icontxt_3_4_1.Visible = false; icontxt_3_4_2.Visible = false; icontxt_3_4_3.Visible = false; icontxt_3_4_4.Visible = false;
                              icontxt_3_5_1.Visible = false; icontxt_3_5_2.Visible = false; icontxt_3_5_3.Visible = false; icontxt_3_5_4.Visible = false;
                              icontxt_3_6_1.Visible = false; icontxt_3_6_2.Visible = false; icontxt_3_6_3.Visible = false; icontxt_3_6_4.Visible = false;
                              icontxt_3_7_1.Visible = false; icontxt_3_7_2.Visible = false; icontxt_3_7_3.Visible = false; icontxt_3_7_4.Visible = false;
                              icontxt_3_8_1.Visible = false; icontxt_3_8_2.Visible = false; icontxt_3_8_3.Visible = false; icontxt_3_8_4.Visible = false;
                              icontxt_3_9_1.Visible = false; icontxt_3_9_2.Visible = false; icontxt_3_9_3.Visible = false; icontxt_3_9_4.Visible = false;
                              icontxt_3_10_1.Visible = false; icontxt_3_10_2.Visible = false; icontxt_3_10_3.Visible = false; icontxt_3_10_4.Visible = false;
                              icontxt_3_11_1.Visible = false; icontxt_3_11_2.Visible = false; icontxt_3_11_3.Visible = false; icontxt_3_11_4.Visible = false;
                          }
                          public void select_hidefront()
                          {
                              // Move and Hide all of the "Front" images that are displayed at program startup
                              
                              // Hide
                              FrontIcon01.Visible = false;
                              FrontIcon02.Visible = false;
                              FrontIcon03.Visible = false;
                              FrontIcon04.Visible = false;
                              FrontIcon05.Visible = false;
                              FrontIcon06.Visible = false;
                              FrontIcon07.Visible = false;
                              FrontIcon08.Visible = false;
                              FrontIcon09.Visible = false;
                              FrontIcon10.Visible = false;
                              FrontLabel.Visible = false;
                              FrontDisplay.Visible = false;
                              
                              // Resize
                              FrontIcon01.Size = new System.Drawing.Size(1, 1);
                              FrontIcon02.Size = new System.Drawing.Size(1, 1);
                              FrontIcon03.Size = new System.Drawing.Size(1, 1);
                              FrontIcon04.Size = new System.Drawing.Size(1, 1);
                              FrontIcon05.Size = new System.Drawing.Size(1, 1);
                              FrontIcon06.Size = new System.Drawing.Size(1, 1);
                              FrontIcon07.Size = new System.Drawing.Size(1, 1);
                              FrontIcon08.Size = new System.Drawing.Size(1, 1);
                              FrontIcon09.Size = new System.Drawing.Size(1, 1);
                              FrontIcon10.Size = new System.Drawing.Size(1, 1);
                              FrontLabel.Size = new System.Drawing.Size(1, 1);
                              FrontDisplay.Size = new System.Drawing.Size(1, 1);
                  
                              // Move
                              FrontIcon01.Location = new System.Drawing.Point(0, 0);
                              FrontIcon02.Location = new System.Drawing.Point(0, 0);
                              FrontIcon03.Location = new System.Drawing.Point(0, 0);
                              FrontIcon04.Location = new System.Drawing.Point(0, 0);
                              FrontIcon05.Location = new System.Drawing.Point(0, 0);
                              FrontIcon06.Location = new System.Drawing.Point(0, 0);
                              FrontIcon07.Location = new System.Drawing.Point(0, 0);
                              FrontIcon08.Location = new System.Drawing.Point(0, 0);
                              FrontIcon09.Location = new System.Drawing.Point(0, 0);
                              FrontIcon10.Location = new System.Drawing.Point(0, 0);
                              FrontLabel.Location = new System.Drawing.Point(0, 0);
                              FrontDisplay.Location = new System.Drawing.Point(0, 0);
                          }
                  
                          // Display Death Knight Class
                          private void FrontIcon01_Click(object sender, EventArgs e)
                          {
                              select_hidefront();
                          }
                  
                          // Display Druid Class
                          private void FrontIcon02_Click(object sender, EventArgs e)
                          {
                              select_hidefront();
                              DruidNS.DruidClass.InitDruid();
                          }
                      }
                  }
                  
                  namespace ImageData
                  {
                      class PublicData
                      {
                  
                          Image[] tempIconArray = {
                              new Bitmap(@"C:\Documents and Settings\Samishii\Desktop\WoW Talent Calc\TalentCalc\ClassDLL\img-druid\druid_1_1_2.png"),
                              new Bitmap(@"C:\Documents and Settings\Samishii\Desktop\WoW Talent Calc\TalentCalc\ClassDLL\img-druid\druid_1_1_3.png"),
                              new Bitmap(@"C:\Documents and Settings\Samishii\Desktop\WoW Talent Calc\TalentCalc\ClassDLL\img-druid\druid_1_2_1.png"),
                              new Bitmap(@"C:\Documents and Settings\Samishii\Desktop\WoW Talent Calc\TalentCalc\ClassDLL\img-druid\druid_1_2_2.png"),
                              new Bitmap(@"C:\Documents and Settings\Samishii\Desktop\WoW Talent Calc\TalentCalc\ClassDLL\img-druid\druid_1_2_4.png")
                          };
                  
                          List<Image> DruidIconList = new List<Image>(tempIconArray);
                          //DruidIconList.AddRange(tempIconArray);
                  
                  
                  
                          public static Bitmap GrayImg(Bitmap original)
                          {
                              Bitmap newBitmap = new Bitmap(original.Width, original.Height);
                              Graphics g = Graphics.FromImage(newBitmap);
                              ColorMatrix colorMatrix = new ColorMatrix(
                                  new float[][]
                                  {
                                      new float[] {.3f, .3f, .3f, 0, 0},
                                      new float[] {.59f, .59f, .59f, 0, 0},
                                      new float[] {.11f, .11f, .11f, 0, 0},
                                      new float[] {0, 0, 0, 1, 0},
                                      new float[] {0, 0, 0, 0, 1}
                                  });
                              ImageAttributes attributes = new ImageAttributes();
                              attributes.SetColorMatrix(colorMatrix);
                              g.DrawImage(original, new Rectangle(0, 0, original.Width, original.Height), 0, 0, original.Width, original.Height, GraphicsUnit.Pixel, attributes);
                              g.Dispose();
                              return newBitmap;
                          }
                      }
                  }
                  ClassLib.cs
                  Code:
                  using System;
                  using System.Collections.Generic;
                  using System.Drawing;
                  using System.Text;
                  using System.Windows.Forms;
                  
                  namespace DLLClass
                  {
                      public class ClassDLL
                      {
                          List<Image> DruidTalentIcons = new List<Image>();
                          List<PictureBox> DruidTalentPB = new List<PictureBox>();
                  
                  
                  
                  
                  
                          public static Icon GetProjectIcon()
                          {
                              Icon ico = new Icon(@"C:\Documents and Settings\Samishii\Desktop\WoW Talent Calc\TalentCalc\ClassDLL\img\warcraft2.ico");
                              return ico;
                          }
                  
                          public static Image GetClassIcon( int CIco )
                          {
                              string[] ImgLoc = new string[] { "DeathKnight", "Druid", "Hunter", "Mage", "Paladin", "Priest", "Rogue", "Shaman", "Warlock", "Warrior" };
                              Image ReturnIcon = new Bitmap(@"C:\Documents and Settings\Samishii\Desktop\WoW Talent Calc\TalentCalc\ClassDLL\img\Icon"+ImgLoc[CIco]+".png");
                              return ReturnIcon;
                          }
                  
                          public Image GetClassBG(int C, int CBg)
                          {
                              Image[] ReturnDruid = new Image[] {
                                  new Bitmap(@"C:\Documents and Settings\Samishii\Desktop\WoW Talent Calc\TalentCalc\ClassDLL\img-druid\DruidBalance.jpg"),
                                  new Bitmap(@"C:\Documents and Settings\Samishii\Desktop\WoW Talent Calc\TalentCalc\ClassDLL\img-druid\DruidFeralCombat.jpg"),
                                  new Bitmap(@"C:\Documents and Settings\Samishii\Desktop\WoW Talent Calc\TalentCalc\ClassDLL\img-druid\DruidRestoration.jpg")
                              };
                              Image[] ReturnDK = new Image[] {
                                  new Bitmap(@"C:\Documents and Settings\Samishii\Desktop\WoW Talent Calc\TalentCalc\ClassDLL\img-dk\DeathKnightBlood.jpg"),
                                  new Bitmap(@"C:\Documents and Settings\Samishii\Desktop\WoW Talent Calc\TalentCalc\ClassDLL\img-dk\DeathKnightFrost.jpg"),
                                  new Bitmap(@"C:\Documents and Settings\Samishii\Desktop\WoW Talent Calc\TalentCalc\ClassDLL\img-dk\DeathKnightUnholy.jpg")
                              };
                              switch (C)
                              {
                                  case 0: return ReturnDK[CBg];
                                  case 1: return ReturnDruid[CBg];
                                  default: return null;
                              }
                          }
                      }
                  }

                  Comment

                  • tlhintoq
                    Recognized Expert Specialist
                    • Mar 2008
                    • 3532

                    #24
                    Good point... Lol. Here goes nothing. One reason I would like to start over, is all that is from when I first started learning the language, and it seems to me is over-bloated, and repeative... Might just be me.

                    Also all the objects in the Form were generated using the Designer...
                    Sometimes starting over is a good thing for exactly the reasons you mention. Sometimes its faster/easier/better to start over so you can start a clean project.

                    But starting new project because you can't find the problem in a current project is bad habit. What happens when you have a very elaborate project with a problem you can't find?

                    For your new project here are a few tips:

                    Code:
                    classicon1.Image = ClassDLL.GetClassIcon(0);
                                classicon2.Image = ClassDLL.GetClassIcon(1);
                                classicon3.Image = ClassDLL.GetClassIcon(2);
                                classicon4.Image = ClassDLL.GetClassIcon(3);
                                classicon5.Image = ClassDLL.GetClassIcon(4);
                                classicon6.Image = ClassDLL.GetClassIcon(5);
                                classicon7.Image = ClassDLL.GetClassIcon(6);
                                classicon8.Image = ClassDLL.GetClassIcon(7);
                                classicon9.Image = ClassDLL.GetClassIcon(8);
                                classicon10.Image = ClassDLL.GetClassIcon(9);
                    These long lists of things really should be lists and loops

                    Code:
                    for (int Index = 0; Index< ClassIconList.Count; Index ++)
                    {
                       ClassIconList[Index].Image = ClassDll.GetClassIcon(Index);
                    }
                    Stuff like this
                    classicon1.Imag e = ClassDLL.GetCla ssIcon(0)
                    is going to confuse the heck out of you. Try to stick with everything indexing the same way. If your list is zero indexed, then stick with that, but item 1 of one list to item 0 of another is a painful way to go.

                    Code:
                                    new Bitmap(@"C:\Documents and Settings\Samishii\Desktop\WoW Talent Calc\TalentCalc\ClassDLL\img-druid\DruidBalance.jpg"),
                    A) Will keep an open link to file on harddrive
                    B) What happens when you load this on another machine, path's change etc?
                    You should either make these images part of the resources of the application, or part of a folder in the installed application path. That way you can always reference that known location.

                    Comment

                    • Samishii23
                      New Member
                      • Sep 2009
                      • 246

                      #25
                      Originally posted by tlhintoq
                      These long lists of things really should be lists and loops
                      That is the EXACT reason for me starting this thread on this website. =P
                      Because when I originally started I didn't know jack about C#. Also I needed help with it. Here I am pretty well learned after all the Q & A going on.

                      Originally posted by tlhintoq
                      A) Will keep an open link to file on harddrive
                      B) What happens when you load this on another machine, path's change etc?
                      You should either make these images part of the resources of the application, or part of a folder in the installed application path. That way you can always reference that known location.
                      I have already done the "Embedded Resource" with all my images, it took a while but I managed to get it into a seperate .dll with the help of GaryTexomo on another thread. (Also my friend is eagerly awaiting the deployment of a usable version of this so hes already seen a few copies of the .exe and hasn't had a problem with the images)

                      I've wanted to have basicly a massive loop for the deployment of these images, since there will be 10 sets of images, over 132 PictureBoxes. While the processing of the loop for the exchange will be slow because of all the images but it'll be easier work on my side.

                      Comment

                      • GaryTexmo
                        Recognized Expert Top Contributor
                        • Jul 2009
                        • 1501

                        #26
                        Originally posted by tlhintoq
                        Just plain bad. First of all "image.jpg" isn't in any way a valid path to a file. All it can possibly do is fail. If it were a valid path, Bitmap(string Path) keeps a link open to the hard drive file until the application closes. This will cause all kinds of issues if you try to move/rename/delete the file.

                        Secondly it doesn't account for any time of error compensation. If the file is damage then this entire function breaks.

                        You should have a dedicated image loading method that can recover from problems, If that method returns an image then you can load it into your list.
                        Not sure I appreciate your comments here. It was just a snippet of code to demonstrate an example. You didn't need to pick it apart and you certainly didn't need to be so insulting, especially when what you said is not completely true. The following I'll say in my defense, but then I'm bowing out of this thread. Good luck, Samishii.

                        1. The file path is valid. It will look in the application directory for that file. A more complete solution may include the file path, but for testing purposes this is sufficient. I've just verified that this is the case. It's easy to set up, feel free to try it.

                        2. I was not aware that Bitmap left an open file handle... fair enough, but allow me to make a simple correction to my code to allow for a copy of the image data to be created.

                        Code:
                        List<Image> imageList = new List<Image>();
                        Bitmap bitmap = new Bitmap("image.jpg");
                        Image bitmapDataCopy = Image.FromHbitmap(bitmap.GetHbitmap();
                        imageList.Add(bitmapDataCopy);
                        I've tested this and no file handles appear to be left.

                        3. As it was just a snippet of code, I didn't include any try/catch blocks. It seems odd that you even bring this up.

                        Comment

                        • Samishii23
                          New Member
                          • Sep 2009
                          • 246

                          #27
                          I hate to bring this thread but up from the depths of the last 20 pages. lol. But...

                          Problem... No compiler errors. No run time errors. But, no images are being seen on the form.

                          _gd is an instance of a text / int32 data class holding default values for the programs usage.

                          Code:
                          public void StartUp() {
                            // StartUp() - Shows the 10 Class Icons for user to select
                            PictureBox[] TempPB = new PictureBox[10];
                            int i = 0;
                            
                            foreach (int TempY in _gd.SUIconY)
                              foreach (int TempX in _gd.SUIconX) {
                                TempPB[i] = new PictureBox();
                                TempPB[i].Location = new Point(TempX, TempY);
                                TempPB[i].Size = new Size(64, 64);
                                TempPB[i].Image = new Bitmap(_gd.DirOther + _gd.ClassIcon[i]);
                                TempPB[i].Visible = true;
                                TempPB[i].BringToFront();
                                Controls.Add(TempPB[i]);
                                i++;
                                }
                              }
                            }
                          I've ran most of the code through a MessageBox to see if any of the dynamic data being seen by the PictureBox code was wrong in anyway. So far it hasn't been. So at this point. I'm lost. =\

                          Suggestions or questions?

                          Comment

                          • GaryTexmo
                            Recognized Expert Top Contributor
                            • Jul 2009
                            • 1501

                            #28
                            Hmmm, have you tried throwing a Console.WriteLi ne(_gd.DirOther + _gd.ClassIcon[i]) in there to see if the path is correct? Maybe it's not finding an image? I'm not sure offhand (you can test) what the Bitmap constructor returns when it can't make an image... I'd guess null but I'm not sure. If it is null, does a PictureBox with a null image work and just not show anything? (again, you can test that fairly quickly)

                            Comment

                            • Samishii23
                              New Member
                              • Sep 2009
                              • 246

                              #29
                              I looked through all the File Paths. Nothing was out of place.

                              Just tried to implement a <List> to do the image storage instead. Same thing. Maybe it is the Bitmap call... Hmm. =\

                              Comment

                              • GaryTexmo
                                Recognized Expert Top Contributor
                                • Jul 2009
                                • 1501

                                #30
                                The paths on disk might be right, but is the file path going into the Bitmap class correct, or is that what you meant?

                                Also, you could try verifying the return of the Bitmap class itself. Is it coming back as null?

                                I definitely think the problem isn't whether or not it's an array or a List here... if no image shows up the best culprit would be the actual image. You're explicitly setting visible to true, so it's not that.

                                Comment

                                Working...