0

I'm working on a MS paint like application in Winforms (C#). Shapes and Pencil tools are done. One thing I'm not sure of how to go about is the Type tool/Text Box. How do I make a dynamic transparent textbox appear on the click of the user (at the location of the click) just like how we see in MS Paint.

So that now the user can type whatever he wants and will remain on the panel. I have found out about DrawString() method, which can be used to repaint after the user completes editing. Only thing is that I have no idea how to make the textbox appear like MS Paint(Transparent). I tried using Labels, but they aren't editable nor does support multiline. Textbox's aren't transparent.

Would appreciate all kinds of help! (Just FYI, this application is to be integrated with a screenshot application, like Lightshot. I did do search for solutions but couldn't find any appropriate solutions)

Kevin Andrid
  • 1,963
  • 1
  • 15
  • 26

1 Answers1

0

This control is better than MS Paints Transparent Textbox: http://www.codeproject.com/Articles/4390/AlphaBlendTextBox-A-transparent-translucent-textbo

Alex Fr provided an excellent set of drawing tools in his DrawTools article and these tools serve as a basis for Draw Tool Redux. In the articles you can see the project is based on MSPaint's code as a C++ port to C#.

I did a drawing tool with these tools in a commercial app and the result was very high quality.

In the DrawTools Redux projects' DrawArea.cs file I made this adjustment to provide users with a Transparent Textbox:

public DrawToolType ActiveTool
{
    get { return activeTool; }
    set
    {
        if (activeTool == value) return;
        if (activeTool == DrawToolType.Text)
        {
            alphaBlendTextBox txt = null;
            foreach (var ctrl in Controls)
            {
                if (ctrl as alphaBlendTextBox!= null)
                {
                    txt = (alphaBlendTextBox)ctrl;
                    break;
                }
            }

            if (txt != null) ((ToolText)tools[(int)activeTool]).txt_Leave(txt, null);

        }
        activeTool = value;
    }
}

I also supported Symbols and colouring, again this code in DrawArea.cs:

public void InsertSymbol(string symbolSyntax)
{
foreach (var obj in Controls)
{
    if (obj as AlphaBlendTextBox.AlphaBlendTextBox != null)
    {
        var txt = ((AlphaBlendTextBox.AlphaBlendTextBox)obj);
        var selectionIndex = txt.SelectionStart;
        int value = int.Parse(symbolSyntax, System.Globalization.NumberStyles.HexNumber);
        symbolSyntax = char.ConvertFromUtf32(value).ToString();
        txt.Text = txt.Text.Insert(selectionIndex, symbolSyntax);
        txt.SelectionStart = selectionIndex + symbolSyntax.Length;
        break;
    }
}
Invalidate();
}

public void ApplyColorToSelected()
{
  int activeLayer = 0;
  foreach (var obj in TheLayers[activeLayer].Graphics.Selection)
  {
      obj.Color = LineColor;
  }
  foreach (var obj in Controls)
  {
      if (obj as AlphaBlendTextBox.AlphaBlendTextBox != null)
      {
          ((AlphaBlendTextBox.AlphaBlendTextBox)obj).ForeColor = LineColor;
      }
  }
  Invalidate();
}

The EyeDropper Colour Picker I got from http://www.codeproject.com/Articles/36540/Adobe-Eyedropper-Control

Jeremy Thompson
  • 61,933
  • 36
  • 195
  • 321