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
G

gwithey

@gwithey
About
Posts
70
Topics
27
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • ResX error
    G gwithey

    I dont know why but it seemed to have repaired itself overnight, i cant get the error to re occur which is odd. Will keep an eye and post the source if it makes another apperance. Thanks for the help George

    C# design help question

  • ResX error
    G gwithey

    Hi this has probably been asked before but i am experiencing difficulties with the following error i encountered while creating a custom user control, it also prevents the form from appearing at design time: Warning 1 ResX file Object of type 'TabHeadingControl.IPage[]' cannot be converted to type 'TabHeadingControl.IPage[]'. Line 185, position 5. cannot be parsed. 185 0 I cannot work out what is going wrong or where this message is originating Thanks in advance George

    C# design help question

  • Creating graphics object
    G gwithey

    Thank you stancrm I saw this however couldnt find a solution as:

    Graphics g;
    // Sets g to a graphics object representing the drawing surface of the
    // control or form g is a member of.
    g = this.CreateGraphics();

    Only works in a control or on a form. Not in a normal C# class Thanx George

    C# graphics question

  • Creating graphics object
    G gwithey

    Thank you Kevinnicol That worked great, i was looking for something like that.

    public static SizeF MeasureString(string s, Font font)
    {
    SizeF result;
    using (var image = new Bitmap(0, 0))
    {
    using (var g = Graphics.FromImage(image))
    {
    result = g.MeasureString(s, font);
    }
    }

        return result;
    }
    

    Did see this example but preffer the below:

    // Generate nodeSize by measuring the name of the node
    Graphics g = Graphics.FromImage(new Bitmap(80, 80));
    m_nodeSize = g.MeasureString(m_name, nodeFont);

    Thanx George

    C# graphics question

  • Creating graphics object
    G gwithey

    Is it possible to create a graphics object in the constructor of a normal calss in order to measure a string? Not using a form or control?

    Graphics g = ?
    m_nodeSize = g.MeasureString(m_name, nodeFont);

    Thanx George

    C# graphics question

  • Localisation
    G gwithey

    Hi i have a question on localisation, I am trying to change the language/culture of the project without ever opening the project in visiual studio. Preferably i need to be able to do this by creating some sort of dictionary which can be translated and then create a new resex file. Does anyone know a way of doing this. Thanx George

    C# question

  • Tree view drawing problem
    G gwithey

    Hi i am trying to write a tree view control however have come accross difficulty in drawing the vertical lines. The bellow method currently works by fining the cumulative height of the last branch it was in and then calls AmountToDeduct(nodes[i].Nodes) to reduce this to the correct height for the next line. However this is very slow. Does anyone know a way i can simply not add nodeheight to the newLineFinishPoint if it is not needed apposed to taking away from the total heigh.

    private Point PositionNodes(List<Node> nodes, Point point)
    {
    // Create new start point for downwards line
    Point newStartPoint = new Point();
    Point newFinishPoint = new Point();
    newStartPoint = point;

         int nodeHeight = nodes\[0\].Size.Height;
    
         // Loop nodes
         for(int i = 0; i &lt; nodes.Count; i++)
         {
            // Set node location and draw
            nodes\[i\].Location = point;
    
            // Increase Y by one line
            point.Y += nodeHeight;
    
            // If node has child nodes
            if (nodes\[i\].Nodes.Count &gt; 0 &amp;&amp; nodes\[i\].Expanded)
            {
               // Call method again on child nodes
               point.Y = PositionNodes(nodes\[i\].Nodes, new Point(point.X + m\_xIndentation, point.Y)).Y;
            }
    
            // Set finishing point of line
            newFinishPoint = point;
            newFinishPoint.Y -= (int)(nodes\[0\].Size.Height \* 0.5);
    
            // If node has only one child and is expanded reduce line by this amount
            if (nodes.Count == 1 &amp;&amp; nodes\[i\].Expanded)
            {
               // Reduce line by child nodes amount
               newFinishPoint.Y -= AmountToDeduct(nodes\[i\].Nodes);
            }
    
            // Add points to list
            m\_linePoints.Add(newStartPoint);
            m\_linePoints.Add(newFinishPoint);
         }
    
         // Cumulative height of nodes
         return point;
      }
    

    Thanks in advance

    C# graphics data-structures help

  • AddRectangle Exception
    G gwithey

    public int Draw(Graphics g)
    {
    DrawNode();

         // Create font for text
         Font nodeFont = new Font(FontFamily.GenericSansSerif, 10f, FontStyle.Regular);
    
         // Fill node if selected
         if (m\_selected)
         {
            g.FillPath(Brushes.Red, m\_gpTextBacking);
            g.DrawString(m\_name, nodeFont, Brushes.White, m\_fontLocation);
         }
         else
         {
            g.DrawString(m\_name, nodeFont, Brushes.Black, m\_fontLocation);
         }
         
         // Draw node backing if hover is true
         if (m\_hover)
         {
            g.DrawPath(Pens.Black, m\_gpTextBacking);
         }
    
         // Draw expand box
         g.FillPath(Brushes.Gray, m\_gpExpandBox);
         g.DrawPath(Pens.Black, m\_gpExpandBox);
    
         // Dispose of graphics paths
    

    ------> //m_gpExpandBox.Dispose();
    ------> //m_gpTextBacking.Dispose();

    Thank you for the help found the soulution. It now works when comment out the indicated lines

    C# graphics help

  • AddRectangle Exception
    G gwithey

    Yes i think it may be related to the graphics path as all its variables have an exception before the line in question is reached. I will have to try and find where it is going wrong. Thanx George

    C# graphics help

  • AddRectangle Exception
    G gwithey

    Yep thats kwl: GraphicsPath.AddRectangle(); (standard method .net) Takes a rectangle as perameter and adds it to graphics path

    private GraphicsPath m_gpExpandBox; // Represents the box for the expand and contract

      public Node(string name)
      {
         // Set the name of this node
         m\_name = name;
    
         // Create objects
         m\_childNodes = new List<Node>();
    

    -----> m_gpExpandBox = new GraphicsPath();
    m_gpTextBacking = new GraphicsPath();
    m_fontLocation = new Point(0, 0);

         // Set size and location of the node
         m\_size = new Size(60, 20);
         m\_location = new Point(0, 0);
      }
    

    There is too much code to include every reference to m_gpExpandBox. It is a graphics path i add to in order to draw an expansion box on a node of a tree view control. Do you think this could be a cause of the problem even though it complains of an invalid perameter. Thanx George

    C# graphics help

  • AddRectangle Exception
    G gwithey

    Hi i seem to be getting an argumentException on the indicated line for no reason that i can see. There is a perameter not valid message however it is, as i create the rectangle and add it straight away.

        // Add two rectangles to graphics path
        Rectangle rectangle = new Rectangle(5, 5, 10, 10);
    
        // Create two rectangles representing the node and expand box
        Rectangle textBacking = new Rectangle(m\_expandBox.Width + (m\_gap \* 2),
        m\_gap - (int)(m\_gap \* 0.5), Size.Width - m\_gap, Size.Height - m\_gap);
    

    -----> m_gpExpandBox.AddRectangle(rectangle);
    m_gpTextBacking.AddRectangle(textBacking);

    Does anyone know why this is happening. I cannot see any information on the net that would reveal the cause of the problem. Thanx George

    C# graphics help

  • How to check a groupbox for checked radiobuttons dynamicaly
    G gwithey

    Thank you for your help. This code now works perfectly, i can use it on the other group boxes on the form too.

    // In Draw mode
    if (rbDraw.Checked == true)
    {
    // Ceck each rb in Shape groupBox
    foreach (Control ctrl in gbShape.Controls)
    {
    if (ctrl is RadioButton)
    {
    // Cast to RadioButton
    RadioButton rb = ctrl as RadioButton;
    if (rb.Checked == true)
    {
    // Set shape selected to the radioButton's tag (shape enum)
    imageViewer1.ShapeSelected = (FileScroller.ImageViewer.Shape)rb.Tag;
    }
    }
    }
    }

    Thank you again George

    C# tutorial question

  • How to check a groupbox for checked radiobuttons dynamicaly
    G gwithey

    That should work only problem being the rb doesnt exsit anymore and ctrl will not allow:

    if (ctrl.Checked == true)

    C# tutorial question

  • How to check a groupbox for checked radiobuttons dynamicaly
    G gwithey

    I don't think i fully understand how that would work.

    class ShapeRadioButton : System.Windows.Forms.RadioButton
    {
    private ImageViewer.Shape m_shape = ImageViewer.Shape.Select;

      public ImageViewer.Shape Shape
      {
         get
         {
            return m\_shape;
         }
         set
         {
            m\_shape = value;
         }
      }
    

    }

    i made the class ^ however it still needs to be set somewhere> do you mean the designer will set each RadioButton to have an instance of "ShapeRadioButton". Then use it in the same way as the tag Thax George

    C# tutorial question

  • How to check a groupbox for checked radiobuttons dynamicaly
    G gwithey

    I have tried this solution however the following error occurs which i do not understand

    Error 1 foreach statement cannot operate on variables of type
    'System.Windows.Forms.GroupBox' because 'System.Windows.Forms.GroupBox'
    does not contain a public definition for 'GetEnumerator'

    The code is as follows:

         // In Draw mode
         if (rbDraw.Checked == true)
         {
            // Ceck each rb in Shape groupBox
            foreach (RadioButton rb in gbShape)
            {
               if (rb.Checked == true)
               {
                  // If checked shape selected = the tag (shape enum set in designer) of the button
                  imageViewer1.ShapeSelected = (FileScroller.ImageViewer.Shape)rb.Tag;
               }
            }
         }
    
    C# tutorial question

  • How to check a groupbox for checked radiobuttons dynamicaly
    G gwithey

    Thank you for the response, that is a great idea and will make things shorter and easier to follow. Can also do this for the other group boxes on the form. Thanx George

    C# tutorial question

  • How to check a groupbox for checked radiobuttons dynamicaly
    G gwithey

    I have come across something and wondered if it can be done.

    private void Shape_CheckedChanged(object sender, EventArgs e)
    {
    // Check and set the draw state that has been selected
    if (rbDraw.Checked)
    {
    if (rbSelectShape.Checked)
    {
    imageViewer1.ShapeSelected = ImageViewer.Shape.Select;
    }
    if (rbDrawRect.Checked)
    {
    imageViewer1.ShapeSelected = ImageViewer.Shape.Rectangle;
    }
    if (rbDrawCircle.Checked)
    {
    imageViewer1.ShapeSelected = ImageViewer.Shape.Circle;
    }
    if (rbDrawTriangle.Checked)
    {
    imageViewer1.ShapeSelected = ImageViewer.Shape.Triangle;
    }
    if (rbLine.Checked)
    {
    imageViewer1.ShapeSelected = ImageViewer.Shape.Line;
    }
    if (rbText.Checked)
    {
    imageViewer1.ShapeSelected = ImageViewer.Shape.Text;
    }
    }
    Console.WriteLine(imageViewer1.ShapeSelected.ToString());
    }

    Above is the code i used to check each radio button however i tried tidying it up with the bellow code and couldn't think of a way to set the enum depending on checked radio button.

    foreach (RadioButton rb in gbShape)
    {
    if (rb.Checked == true)
    {
    imageViewer1.ShapeSelected = ImageViewer.Shape.Circle; // How can make dynamic?
    }
    }

    Any ideas Thanx in advance

    C# tutorial question

  • Chnging a combo box entry
    G gwithey

    Thank you for all of the replies. I got everything working now there was alot to it as the shapes can be selected by the mouse too so this also had to change the comboBox :

    void imageViewer1_Clicked(object sender, EventArgs e)
    {
    // When shape picked select appropriate entry in the combo box
    if (imageViewer1.ListOfShapes.Count > 0)
    {
    for (int i = 0; i < comboBox1.Items.Count; i++)
    {
    if ((string)comboBox1.Items[i] == imageViewer1.ListOfShapes[imageViewer1.SelectedShapeIndex].Name) // imageViewer1.ListOfShapes[imageViewer1.SelectedShapeName].Name)
    {
    comboBox1.SelectedIndex = i;
    m_comboBoxCurrentIndex = i;
    }
    }
    }
    }

    Above and below (solution) may not be pretty but it works

    case (char)Keys.Enter:
    if (comboBox1.SelectedIndex != -1)
    {
    // Set current selected index and clear text
    m_comboBoxCurrentIndex = comboBox1.SelectedIndex;
    comboBox1.Text.Remove(0, comboBox1.Text.Length);

                  // Rename shape in image viewer
                  imageViewer1.RenameShape("test");
    
                  // Set text for selected item
                  comboBox1.Items\[m\_comboBoxCurrentIndex\] = "test";
                  comboBox1.Text = "";
               }
    

    Thanx George

    C# help

  • Chnging a combo box entry
    G gwithey

    I have tried this but cannot find a way of getting it to work for me : I dont know how to set the selected index's text property

    C# help

  • Chnging a combo box entry
    G gwithey

    Thanx have tried this and the text does change but when i drop down the list test is not there.

    case (char)Keys.Enter:
    comboBox1.Text.Remove(0, comboBox1.Text.Length);
    imageViewer1.RenameShape("test");
    comboBox1.Text = "test";
    break;

    It just displays shape1 , shape2 .........

    C# help
  • Login

  • Don't have an account? Register

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