Bonsoir,
je cherche avant tout, sans utiliser de lib, avoir une textbox transparente ( multiligne mais bon ca c est natif)
et si possible qu il justifi le text ( comme on dit dans word ...)
PS: comment on dit "justifié" en anglais ?
voila
merci !
Version imprimable
Bonsoir,
je cherche avant tout, sans utiliser de lib, avoir une textbox transparente ( multiligne mais bon ca c est natif)
et si possible qu il justifi le text ( comme on dit dans word ...)
PS: comment on dit "justifié" en anglais ?
voila
merci !
y a mieux que ca ?
http://www.codeproject.com/KB/edit/T...ntTextBox.aspx
euhh comment on fait pour ajouter la reference API:
Win32.WM_PAINT par exemple ??
:x
J ai pas vu... en tout cas le code tel quel ne compil pas
malgres un using Microsoft.Win32; Win32 n existe pas dans le contexte actuel.... en plus c est pas de la vrai transparence il triche il passe par une image le bougre...
j ai essaye de mettre ca dans une clase herite de textbox ....
mais ca marche pas
Citation:
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x00000020; //WS_EX_TRANSPARENT
return cp;
}
}
ah m***e, je croyais que les sources étaient disponibles en téléchargement... :aie:
Win32 c'est une classe qu'il a déclaré, et WM_PAINT une constante qui correspond au message Windows du même nom. Tu peux trouver les valeurs WM_* (et d'autres constantes) dans le fichier WinUser.h qui est normalement placé ici :
C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include
La classe Win32 contient aussi la déclaration de l'API Windows SendMessage :
Code:
1
2 [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)] static extern IntPtr SendMessage(IntPtr hWnd, Int32 Msg, IntPtr wParam, IntPtr lParam);
ah je te remercie !
jvais tester ça....
mais je pense que jvais être déçu vu les commentaires :/
voila du code qui compile :), ca marche impec dans mon cas...Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91 using System; using System.Collections.Generic; using System.Text; using System.Windows.Forms; using System.Drawing; using System.Runtime.InteropServices; using System.Drawing.Imaging; namespace TransparentTextBox { public class TransparentTextBox : TextBox { PictureBox pictureBox = new PictureBox(); public TransparentTextBox() { pictureBox.Dock = DockStyle.Fill; this.Controls.Add(pictureBox); } protected override void WndProc(ref Message m) { base.WndProc(ref m); switch (m.Msg) { case 0x000F: Bitmap bmpCaptured = new Bitmap(this.ClientRectangle.Width, this.ClientRectangle.Height); Bitmap bmpResult = new Bitmap(this.ClientRectangle.Width, this.ClientRectangle.Height); Rectangle r = new Rectangle(0, 0, this.ClientRectangle.Width, this.ClientRectangle.Height); CaptureWindow(this, ref bmpCaptured); this.SetStyle(ControlStyles.SupportsTransparentBackColor, true); this.BackColor = Color.Transparent; ImageAttributes imgAttrib = new ImageAttributes(); ColorMap[] colorMap = new ColorMap[1]; colorMap[0] = new ColorMap(); colorMap[0].OldColor = Color.White; colorMap[0].NewColor = Color.Transparent; imgAttrib.SetRemapTable(colorMap); Graphics g = Graphics.FromImage(bmpResult); g.DrawImage(bmpCaptured, r, 0, 0, this.ClientRectangle.Width, this.ClientRectangle.Height, GraphicsUnit.Pixel, imgAttrib); g.Dispose(); pictureBox.Image = (Image)bmpResult.Clone(); break; case 0x0114: case 0x0115: this.Invalidate(); // repaint // if you use scrolling then add these two case statements break; } } [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)] static extern IntPtr SendMessage(IntPtr hWnd, Int32 Msg, IntPtr wParam, IntPtr lParam); private static void CaptureWindow(Control control, ref Bitmap bitmap) { Graphics g = Graphics.FromImage(bitmap); int i = (int)(0x00000004L | 0x00000008L); IntPtr iPtr = new IntPtr(14); IntPtr hdc = g.GetHdc(); SendMessage(control.Handle, 0x0317, hdc, iPtr); g.ReleaseHdc(hdc); g.Dispose(); } } }
merci tom
bon maintenant.... il me reste plus qu'a avoir l'AutoSize, et si possible du texte justifié ( mais ca c'est le maxi bonus)
j'ai ajouté:
mais ca n'a pas vraiment l'air de fonctionner ...Code:
1
2
3
4
5
6
7
8
9
10
11
12 [BrowsableAttribute(true)] public override bool AutoSize { get { return base.AutoSize; } set { base.AutoSize = value; } }
tomlev
j'aimerais que ma public class TransparentTextBox : TextBox, se retaille automatiquement à son contenu
ah ok... en fait AutoSize est une propriété déclarée dans Control mais qui n'a de sens que pour certains contrôles, dont TextBox ne fait pas partie. Il faut donc l'overrider pour ajuster la taille en fonction du contenu, selon ta propre logique... Par exemple, quand le texte change tu peux calculer la taille du texte avec la classe TextRenderer, et donner cette taille (plus une marge) à la TextBox.
Exemple :
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 public class AutoSizeTextBox : TextBox { private bool _autoSize = false; [Browsable(true), DefaultValue(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] public override bool AutoSize { get { return _autoSize; } set { _autoSize = value; if (_autoSize) this.Size = ComputeSize(); } } protected override void OnTextChanged(EventArgs e) { base.OnTextChanged(e); if (this.AutoSize) { this.Size = ComputeSize(); } } protected System.Drawing.Size ComputeSize() { System.Drawing.Size s = TextRenderer.MeasureText(this.Text, this.Font); int width = Math.Min(Math.Max(s.Width + 3, this.MinimumSize.Width), this.MaximumSize.Width); int height = Math.Min(Math.Max(s.Height + 8, this.MinimumSize.Height), this.MaximumSize.Height); return new System.Drawing.Size(width, height); } }
Merci du coup de main, (j'aimerai aider autant que tu aides)
Bon manque plus que de justifier le texte... mais la je crois que jvais laisser tomber pour l'option
Je posterais le code propre de cette textbox d'ici peu !
Merci
eheh...
j'ai vu en effet que pas mal de choses etaient gérée nativement avec le 3.5...
mais ce n'est pas moi qui choisit la techno, helas...