Hallo,<br>
ich möchte eine Komponente programmieren. Dafür muß ich wissen, wieviel <br>
Zeichen in den sichtbaren Bereich einer Textbox passen.<br>
ich verwende die Funktion "GetTextExtentExPoint".<br>
Sie gibt aber immer nur "false" zurück.<br>
GetLastError bringt die Fehlernummer 126 = Modul nicht gefunden.<br>
Was mache ich falsch ? <br>
<br><br>
<PRE>
[DllImport("gdi32.dll" ,CharSet = CharSet.Auto )]
public extern static long GetTextExtentExPoint
(
IntPtr hdc, // handle to DC
[MarshalAs (UnmanagedType.LPTStr)]
string lpszStr, // character string
int cchString, // number of characters
int nMaxExtent, // maximum width of formatted string
ref IntPtr lpnFit, // maximum number of characters
ref IntPtr alpDx, // array of partial string widths
ref IntPtr lpSize // string dimensions
);
[DllImport("Kernel32.dll")]
public extern static uint GetLastError();
public struct strSize
{
public long lx;
public long ly;
}
private void button1_Click(object sender, System.EventArgs e)
{
int nFit = 0;
IntPtr lpnFit = Marshal.AllocHGlobal(Marshal.SizeOf(nFit));
strSize mySize;
mySize.lx = 0;
mySize.ly = 0;
IntPtr lpSize = Marshal.AllocHGlobal(Marshal.SizeOf(mySize));
IntPtr alpDx = IntPtr.Zero;
textBox1.Text = "aaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbb";
Graphics g = textBox1.CreateGraphics();
IntPtr hdc = g.GetHdc();
long nResult = GetTextExtentExPoint(hdc, textBox1.Text,textBox1.Text.Length,
80,ref lpnFit,ref alpDx,ref lpSize );
uint nTest = GetLastError();
}
</PRE>
ich möchte eine Komponente programmieren. Dafür muß ich wissen, wieviel <br>
Zeichen in den sichtbaren Bereich einer Textbox passen.<br>
ich verwende die Funktion "GetTextExtentExPoint".<br>
Sie gibt aber immer nur "false" zurück.<br>
GetLastError bringt die Fehlernummer 126 = Modul nicht gefunden.<br>
Was mache ich falsch ? <br>
<br><br>
<PRE>
[DllImport("gdi32.dll" ,CharSet = CharSet.Auto )]
public extern static long GetTextExtentExPoint
(
IntPtr hdc, // handle to DC
[MarshalAs (UnmanagedType.LPTStr)]
string lpszStr, // character string
int cchString, // number of characters
int nMaxExtent, // maximum width of formatted string
ref IntPtr lpnFit, // maximum number of characters
ref IntPtr alpDx, // array of partial string widths
ref IntPtr lpSize // string dimensions
);
[DllImport("Kernel32.dll")]
public extern static uint GetLastError();
public struct strSize
{
public long lx;
public long ly;
}
private void button1_Click(object sender, System.EventArgs e)
{
int nFit = 0;
IntPtr lpnFit = Marshal.AllocHGlobal(Marshal.SizeOf(nFit));
strSize mySize;
mySize.lx = 0;
mySize.ly = 0;
IntPtr lpSize = Marshal.AllocHGlobal(Marshal.SizeOf(mySize));
IntPtr alpDx = IntPtr.Zero;
textBox1.Text = "aaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbb";
Graphics g = textBox1.CreateGraphics();
IntPtr hdc = g.GetHdc();
long nResult = GetTextExtentExPoint(hdc, textBox1.Text,textBox1.Text.Length,
80,ref lpnFit,ref alpDx,ref lpSize );
uint nTest = GetLastError();
}
</PRE>
Comment