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
D

Duong Tien Nam

@Duong Tien Nam
About
Posts
51
Topics
27
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • draw rich text in a custom control
    D Duong Tien Nam

    I'm writing a control similar to visio to draw shapes and text, now I want to support rich text drawing into my control. I searched the web and found what they call "windowless rich text control" but it does not have code for C#, below is what I tried to do but it is not work:

    namespace WindowsFormsApplication1
    {
    [Guid("c5bdd8d0-d26e-11ce-a89d-00aa006cadc5")]
    [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
    public interface ITextHost
    {
    IntPtr TxGetDC();
    IntPtr TxReleaseDC(IntPtr hdc);
    }

    public partial class Form1 : Form, ITextHost
    {
        \[DllImport("riched20.dll")\]
        private static extern int CreateTextServices(
          \[MarshalAs(UnmanagedType.IUnknown)\] object punkOuter,
          ITextHost pITextHost,
          \[MarshalAs(UnmanagedType.IUnknown), Out\] out object ppUnk);
    
        public Form1()
        {
            InitializeComponent();
            this.Load += new EventHandler(Form1\_Load);
        }
    
        void Form1\_Load(object sender, EventArgs e)
        {
            object ppUnk = null;
            int result = CreateTextServices(null, this, out ppUnk);
        }
    
        #region ITextHost Members
    
        public IntPtr TxGetDC()
        {
            return this.Handle;
        }
    
        public IntPtr TxReleaseDC(IntPtr hdc)
        {
            return IntPtr.Zero;
        }
    }
    

    }

    When run into the method CreateTextServices, it keeps saying that the memory is corrupted. I don't know what I did wrong in the code. And I stuck with it. Please help me with that, thanks for your concern.

    C# help csharp graphics performance

  • Can a control have multi parents?
    D Duong Tien Nam

    Pity :( It's a MDI application, user can even move the MDI forms around and align them parallely to work together. Now I have many troubles synchronize them. Anyway, thanks for you answers, I can use them in some other cases.

    C# data-structures help question

  • Can a control have multi parents?
    D Duong Tien Nam

    Hi every body, I have to forms, each form has a tree that is exactly the same with the other, the best way is to use one tree control for both form, but I realize that when you add a control to another parent, the former parent will remove it from it's Controls' list. You have any idea to solve my problem? Thanks a lot! Regards.

    C# data-structures help question

  • Can I ask questions about printer HP-GL/2 language here?
    D Duong Tien Nam

    I am writing a PCL renderer library for my draw control and stuffed in some detail. I wonder that anyone here can help me solve them, or are there any forums talk about this? Because the .NET graphics supports some specical pattern fill in HatchBrush object, to render it in PCL, I need to use RF (user defined raster fill) command along with FT (fill type) command to fill my rectangle. The problem is the hatch brush support foreground and backgroud color for its fill, but the HP-GL only support black and white fill. I read in some document and below is what they says about the pattern's color: Pen Number - Represents a pixel in the pattern being defined and indicates its color (black or white). 0 - White >0 - Black but other document says: The pen_number parameters define pixel left to right, top to bottom. Each pixel takes on the color of the specified pen (negative numbers a treated as zero). It's seems that the first one is what I meet, so what should I do the get the second effect? Please help me, thanks alot.

    IT & Infrastructure help csharp graphics regex question

  • How to draw combine shapes like Visio?
    D Duong Tien Nam

    Hi, I'm now coding a tool to draw shapes like Visio. I notice that in Visio there are some functions to combine 2 or more shapes like Union, Intersect, Combine..., I don't know how to do it in C#. Currently I create a GraphicsPath, then assign some rect, ellipse to it, then create a Region and add the GraphicsPath to it. I can then fill the region, but for the outline, I don't know how to draw. And it's just similar to Union in Visio, what about other? Thanks alot for your help.

    C# csharp help tutorial question

  • Maybe a C# bug
    D Duong Tien Nam

    The reason I have to change the graphics' PageUnit to inch because I want all to draw in inch measurement. If you test you code above, you will see that it draws a dotted line with 1 inch width. So you need to convert 1 inch width pen to 1 pixel with pen with PixelToInch method above. I hope you can understand my explanation because English is not native language. Thank you.

    IT & Infrastructure help csharp question learning

  • Maybe a C# bug
    D Duong Tien Nam

    I'm sorry not to show you enough information. The first thing I forget is the PageUnit change for graphics object

    Graphics g = e.Graphics;
    g.PageUnit = GraphicsUnit.Inch;
    Pen p = new Pen(Color.Red, UnitConverter.PixelToInch(1));
    p.DashStyle = DashStyle.Dot;
    g.DrawLine(p, 1, 1, 50, 1);

    The second: UnitConvert is just a class I write to change the pen width:

    public static class UnitConverter
    {
    static float _dpi = 96;
    public static float Dpi
    {
    get { return UnitConverter._dpi; }
    set { UnitConverter._dpi = value; }
    }

        public static float PixelToUnit(double pixel, GraphicsUnit unit)
        {
            double result = 0;
            switch (unit)
            {
                case GraphicsUnit.Inch:
                    result = pixel / Dpi;
                    break;
    
                case GraphicsUnit.Pixel:
                    result = pixel;
                    break;
    
                case GraphicsUnit.Millimeter:
                    result = pixel / (Dpi / 2.54) \* 10;
                    break;
    
                case GraphicsUnit.Point:
                    result = pixel / (Dpi / 72);
                    break;
            }
    
            return (float)result;
        }
    }
    

    }

    IT & Infrastructure help csharp question learning

  • Maybe a C# bug
    D Duong Tien Nam

    I try this code by overriding control's OnPaint method:

    Pen p = new Pen(Color.Red, UnitConverter.PixelToInch(1));
    p.DashStyle = DashStyle.Dot;
    g.DrawLine(p, 1, 1, 50, 1);

    The result seems like it draws a dot with 1 inch width, like this:

    __________ __________ __________ __________

    but if you change the pen width to 2 pixels (means 0.00xx inch of course), we have the correct result:

    ...................................................................

    (in 2 pixel width). am I misunderstand the .NET method to draw line or is it a bug? Please help me to solve this problem, thank for you help.

    IT & Infrastructure help csharp question learning

  • CruiseControl.NET problem!
    D Duong Tien Nam

    I know it's not suitable to ask a question like this here, but I can't find any site that discuss about my problem. So if you know any, pls let me know, I really appriciate that. My C# solution uses more than 1 project and each one located at difference location in VSS, like this: $/MainProject $/ReferenceLibrary1 $/ReferenceLibrary2 I want to use CCNet to contiuous build my solution, but the problem is use can just config the source control tab to get 1 VSS location for one project, so I have to manually get all reference libraries before I can force my main project run. So how can I config my CC to get code from all 3 locations and then build. Of course I can use $/ but it will get all the code from source safe, It's not really good huh!? Please help me, Thank you for reading.

    IT & Infrastructure question csharp help learning

  • Graphics problems
    D Duong Tien Nam

    Yes, its fast drawing, but not as fast as Word does. I just use and old-fashion double-buffer drawing techique. For object moving, I use GDI rubberband line and curve to draw. It not good for now, fast on drawing rectangle, but for ellipse, I have to flatten the graphics path, so it's extremly slow when drawing moving ellipse. I will show you the code (or even send mail to you all the source code) the next Monday, because I don't bring code to home and today is Saturday :D Anyway, do you interest of building a canvas component that can draw and transform shapes, group shapes, support zooming, ect or know any body experienced about this?...... I'm stuck on this now because I working alone :((

    C# graphics help

  • Graphics problems
    D Duong Tien Nam

    I understand your idea that create the transformation status in each shape instance, for example: float _scaleOffsetX; float _scaleOffsetY; float _rotateAngle; float _movingOffsetX; float _movingOffsetY; and then use this information to draw the shape. But did you notice my _border field? It is the bound of the shape. Client will use it to determine the shape's position and size, so it has to change when any transformation of the shape has done. The problem is when you rotate the shape, you have to re-calculate the _border again and of course its not accuracy. I know you and I is so close to the final solution, but it's still the gap... I will think about your solution more carefully.

    C# graphics help

  • Graphics problems
    D Duong Tien Nam

    OK, but it is so BIG :( This is my main class of shape, I hope it's not very complicated to learn using System; using System.Collections.Generic; using System.Text; using System.Drawing; using System.Drawing.Drawing2D; using System.Windows.Forms; using EZDesignerCore.ShapeAttribute; using EZDesignerCore.ShapeApperance; using Utils.GraphicsUtils; namespace EZDesignerCore.Shape { public abstract class AbstractShape : ICloneable, IDisposable { #region properties protected string _name; public string Name { get { return _name; } set { _name = value; } } protected string _text; public string Text { get { return _text; } set { _text = value; } } protected RectangleF _border; public RectangleF Border { get { return _border; } } public virtual PointF Location { get { return _border.Location; } set { _border.Location = value; } } public virtual SizeF Size { get { return _border.Size; } set { _border.Size = value; } } protected Spot _spot; public Spot Spot { get { return _spot; } } protected Apperance _apprerance; public Apperance Apprerance { get { return _apprerance; } } protected Restriction _restriction; public Restriction Restriction { get { return _restriction; } } protected State _state; internal State State { get { return _state; } set { _state = value; } } protected float _rotateDegree; public float RotateDegree { get { return _rotateDegree; } set { _rotateDegree = value; } } protected TextBox _editTextBox; public TextBox EditTextBox { get { return _editTextBox; } } #endregion PointF _startPoint = PointF.Empty; Control _control = null; Graphics _graphics = null; GraphicsPath _path; GraphicsPath _oldPath = null; protected float[] _childShapeRotateDegrees; #region constructor public AbstractShape() { _spot = new Spot(); _apprerance = new Apper

    C# graphics help

  • Graphics problems
    D Duong Tien Nam

    It's slow and not accuracy not because of my drawing method (i use double buffer and other fast techique to draw) but because of the transformation agorithyms. I searched the Internet but dont see anything...

    C# graphics help

  • Graphics problems
    D Duong Tien Nam

    It is like you edit a canvas in Microsoft Word, I dont think I have to use DirectX :(

    C# graphics help

  • Graphics problems
    D Duong Tien Nam

    I am coding a program that drawing shapes in canvas. Shapes can move, rotate, resize and group together. I tried many ways (using Matrix...) but it still slow and not accuracy (due to rotate action). Anybody knows any program do like me or any document about this problems, help me!!!! Thank for your help!

    C# graphics help

  • User control problem
    D Duong Tien Nam

    I have a user control and I don't want some properties automatically generate value by the designer. I search MSDN and just see that I can use DesignOnlyAttribute class but it is not suitable for my situation. How could I do that? Thank for your help.

    C# help question

  • How to handle a event in Windows Application
    D Duong Tien Nam

    If Form1 is your main form and Form2 is your subform, on the button click event write Form2 f = new Form2(); f.Show(); this.Hide(); Although we should remove memory use for Form1 but I dont know how too :(

    C# help tutorial

  • Memory leaks!
    D Duong Tien Nam

    Hi all, I have a complicated form. I call that form from my main form and then close it. After close I call GC.Collect() to ensure that all the memory used for the form has been removed. But it still exited. I load sos.dll and use !dumpheap -stat command to show memory and see that my form and all controls and objects the form use still existed. I debug for a long time, remove delegates, dispose disposable objects etc. but the form didnt' go. So how can I know which object hold reference to the form? (they call them root reference as I remember). Any article, any tool to solve my problems. It's critical, please help me. Regards,

    C# question debugging performance help

  • problems with memory.
    D Duong Tien Nam

    I have some problems with destroying object after using. 1. How can I dispose the form with many events registered and some global fields that has to be destroyed? Or it will destroy automatically? 2. If my class registers some events from other objects (use +=), do I have to unregister all the events (use -=)on its Dispose() method? I afraid that the objects firing events will stay still in heap if I dont do that. Thx for you answers.

    C# question performance

  • Justify text
    D Duong Tien Nam

    I got the problem when using Graphics object to draw text, like this Graphics g; g.DrawString("Text", font, brush, rect, format); with format is an instance of System.Drawing.StringFormat No way to strect the text lines to have the same width :(( Thanks for your answer anyway.

    C# graphics help tutorial
  • Login

  • Don't have an account? Register

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