Die Tags müssen ja auch richtig in dem Stream "stehen". Sie werden an das Ende der Datei geschrieben. Schau doch mal nach ob die Tags dort überhaupt ankommen.
danke für die schnelle Hilfe hab mich wohl bissl blöd beim googeln angestellt.. Man könnt ja auch fast von allein darauf kommen das DrawImage(img, 0, 0) einfach ein ghost von DrawImageUnscaled(img, 0,0) ist...
also ich hab ein Programm geschrieben was versucht Orthodrome (Luftlinien) auf eine Plattkarte zu zeichnen. Wie auch immer diese Plattkarte ist ein .jpg und wird zur Laufzeit als Ressource geladen. Wenn ich nun die Plattkarte mit dc.DrawImage(image, 0, 0); Zeichne ist diese weitaus größer als wenn ich sie mit dc.DrawImage(image, new Rectangle(0, 0, image.Width, image.Height)); zeichne.
TextBox t = new TextBox();
/* Hier das Format der TB definieren. Wie Jack schon schrieb kannst du diese aus dem Designer holen. */
this.Controls.Add(t);
[OFFTOPIC] Der Designer spinnt eh manchmal ein bisschen ich hab auch bspw einen namespace x dadrin eine control x und eine Form z in der Form z das control x und die form schmeisst immer einen compiler Fehler...[/OFFTOPIC]
Was aber auch sein kann das du eventuell nach dem InitializeComponents() in dem ctor irgentwie die Liste Clearst? Kann ja mal passieren... ^^
Also wie der Titel schon aussagt brauche ich die CreateParams für eine Form. Also ich möchte nur den im vista, win7 fall den Themen-Rahmen ohne ControlBox oder Title bar haben. Leider finde ich die Params nicht.
GetString gibt die Anzahl der geschriebene Zeichen im Argument Key zurück. Das brauchst du, damit du in C# weißt, wieviele Zeichen du aus dem StringBuilder wieder rausholen musst.
? Da das ganze ja ein String ist kann man auch einfach den Speicher bis zum null terminator lesen. Wüsste nicht warum man die Anzahl der Zeichen braucht?!
RectangleF Bereich = new RectangleF(55,66,100,100);
int dx = 5, dy = 5;
for (int i = 0; i < 5; i++)
{
width4 += dx;
height4 += dy;
Invalidate(Bereich);
Thread.Sleep(5);
}
Ich frag mich gerade was diese Statements überhaupt bewirken sollen? Für mich sieht das aus als fehlen dir Grundkenntnisse der Programmierung. Ohne dir nahe treten zu wollen würd ich sagen du solltest mal ganz von vorne anfangen und dir ein Handbuch oder ähnliches zulegen!
Diese Klasse ist abgeleitet von System.IO.Filestream und überschreibt die Funktionen Read(), Write(), ReadByte() und WriteByte(). In den funktionen wird eine XOR-Verknüpfung mit den Bytes, einem Offset, der Position des Streams und einem Schlüssel verwendet um die Bytes zu verschlüsseln.
Ein Testprojekt habe ich gleich mal mit beigepackt. Ich bitte um Vorschläge zur Verbesserung. :D
using System.IO;
using System.Security.Cryptography;
namespace System.IO.Cryption
{
public enum CryptStreamKeyLockAlgorithm
{ None = 0, MD5, SHA1, SHA256, SHA384, SHA512, RIPEMD160 }
/// <summary>
/// Provides a generic XOR based cryption stream.
/// </summary>
public class CryptStream : FileStream
{
public const CryptStreamKeyLockAlgorithm DefaultKeyLockAlgorithm = CryptStreamKeyLockAlgorithm.None;
public const uint DefaultLoff = 0;
#region Fields
private CryptStreamKeyLockAlgorithm alg;
private byte[] key;
private uint loff;
#endregion
#region Members
/// <summary>
/// Gets the generated hash for the key.
/// </summary>
public byte[] Key { get { return key; } }
/// <summary>
/// Gets the KeyLockAlgorithm for this instance.
/// </summary>
public CryptStreamKeyLockAlgorithm KeyLockAlg { get { return alg; } }
#endregion
#region Ctor's
/// <summary>
/// Creates a new Crypto Stream.
/// </summary>
/// <param name="key">Key for the encryption/decryption.</param>
/// <param name="file">Relative or absolute path to the file.</param>
/// <param name="fmod">Operation mode.</param>
public CryptStream(byte[] key, string file, FileMode fmod)
: base(file, fmod)
{
if (key.Length ≤ 0)
throw new NotSupportedException("key have to be an byte array with at least one byte of lenght.");
this.alg = DefaultKeyLockAlgorithm;
this.key = key;
this.loff = DefaultLoff;
init();
}
/// <summary>
/// Creates a new Crypto Stream.
/// </summary>
/// <param name="key">Key for the encryption/decryption.</param>
/// <param name="file">Relative or absolute path to the file.</param>
/// <param name="fmod">Operation mode.</param>
public CryptStream(byte[] key, string file, FileMode fmod, CryptStreamKeyLockAlgorithm alg)
: base(file, fmod)
{
if (key.Length ≤ 0)
throw new NotSupportedException("key have to be an byte array with at least one byte of lenght.");
this.alg = alg;
this.key = key;
this.loff = DefaultLoff;
init();
}
/// <summary>
/// Creates a new Crypto Stream.
/// </summary>
/// <param name="key">Key for the encryption/decryption.</param>
/// <param name="file">Relative or absolute path to the file.</param>
/// <param name="fmod">Operation mode.</param>
public CryptStream(string key, string file, FileMode fmod)
: base(file, fmod)
{
if (key.Length ≤ 0)
throw new NotSupportedException("key have to be an string with at least one char inside.");
this.alg = DefaultKeyLockAlgorithm;
this.key = Text.UnicodeEncoding.ASCII.GetBytes(key);
this.loff = DefaultLoff;
init();
}
/// <summary>
/// Creates a new Crypto Stream.
/// </summary>
/// <param name="key">Key for the encryption/decryption.</param>
/// <param name="file">Relative or absolute path to the file.</param>
/// <param name="fmod">Operation mode.</param>
public CryptStream(string key, string file, FileMode fmod, CryptStreamKeyLockAlgorithm alg)
: base(file, fmod)
{
if (key.Length ≤ 0)
throw new NotSupportedException("key have to be an string with at least one char inside.");
this.alg = alg;
this.key = Text.UnicodeEncoding.ASCII.GetBytes(key);
this.loff = DefaultLoff;
init();
}
/// <summary>
/// Creates a new Crypto Stream.
/// </summary>
/// <param name="key">Key for the encryption/decryption.</param>
/// <param name="file">Relative or absolute path to the file.</param>
/// <param name="fmod">Operation mode.</param>
public CryptStream(byte[] key, string file, uint loff, FileMode fmod)
: base(file, fmod)
{
if (key.Length ≤ 0)
throw new NotSupportedException("key have to be an byte array with at least one byte of lenght.");
this.alg = DefaultKeyLockAlgorithm;
this.key = key;
this.loff = loff;
init();
}
/// <summary>
/// Creates a new Crypto Stream.
/// </summary>
/// <param name="key">Key for the encryption/decryption.</param>
/// <param name="file">Relative or absolute path to the file.</param>
/// <param name="fmod">Operation mode.</param>
public CryptStream(byte[] key, string file, uint loff, FileMode fmod, CryptStreamKeyLockAlgorithm alg)
: base(file, fmod)
{
if (key.Length ≤ 0)
throw new NotSupportedException("key have to be an byte array with at least one byte of lenght.");
this.alg = alg;
this.key = key;
this.loff = loff;
init();
}
/// <summary>
/// Creates a new Crypto Stream.
/// </summary>
/// <param name="key">Key for the encryption/decryption.</param>
/// <param name="file">Relative or absolute path to the file.</param>
/// <param name="fmod">Operation mode.</param>
public CryptStream(string key, string file, uint loff, FileMode fmod)
: base(file, fmod)
{
if (key.Length ≤ 0)
throw new NotSupportedException("key have to be an string with at least one char inside.");
this.alg = DefaultKeyLockAlgorithm;
this.key = Text.UnicodeEncoding.ASCII.GetBytes(key);
this.loff = loff;
init();
}
/// <summary>
/// Creates a new Crypto Stream.
/// </summary>
/// <param name="key">Key for the encryption/decryption.</param>
/// <param name="file">Relative or absolute path to the file.</param>
/// <param name="fmod">Operation mode.</param>
public CryptStream(string key, string file, uint loff, FileMode fmod, CryptStreamKeyLockAlgorithm alg)
: base(file, fmod)
{
if (key.Length ≤ 0)
throw new NotSupportedException("key have to be an string with at least one char inside.");
this.alg = alg;
this.key = Text.UnicodeEncoding.ASCII.GetBytes(key);
this.loff = loff;
init();
}
#endregion
#region Initializing
private void init()
{
MD5 md5;
SHA1 sha1;
SHA256 sha256;
SHA384 sha384;
SHA512 sha512;
RIPEMD160 ripemd160;
switch (alg)
{
case CryptStreamKeyLockAlgorithm.MD5:
md5 = MD5.Create();
key = md5.ComputeHash(key);
md5.Clear();
break;
case CryptStreamKeyLockAlgorithm.SHA1:
sha1 = SHA1.Create();
key = sha1.ComputeHash(key);
sha1.Clear();
break;
case CryptStreamKeyLockAlgorithm.SHA256:
sha256 = SHA256.Create();
key = sha256.ComputeHash(key);
sha256.Clear();
break;
case CryptStreamKeyLockAlgorithm.SHA384:
sha384 = SHA384.Create();
key = sha384.ComputeHash(key);
sha384.Clear();
break;
case CryptStreamKeyLockAlgorithm.SHA512:
sha512 = SHA512.Create();
key = sha512.ComputeHash(key);
sha512.Clear();
break;
case CryptStreamKeyLockAlgorithm.RIPEMD160:
ripemd160 = RIPEMD160.Create();
key = ripemd160.ComputeHash(key);
ripemd160.Clear();
break;
default:
case CryptStreamKeyLockAlgorithm.None:
break;
}
}
#endregion
#region Overrides
public override int Read(byte[] array, int offset, int count)
{
int rc = base.Read(array, offset, count);
long p = Position - count;
for (int i = offset; i < rc; i++)
{
int idx = (int)(p % key.Length);
array[i] ^= (byte)(key[idx] ^ (p++ + loff));
}
return rc;
}
public override void Write(byte[] array, int offset, int count)
{
long p = Position;
for (int i = offset; i < count; i++)
{
int idx = (int)(p % key.Length);
array[i] ^= (byte)(key[idx] ^ (p++ + loff));
}
base.Write(array, offset, count);
}
public override int ReadByte()
{
long p = Position;
byte b = (byte)base.ReadByte();
b ^= (byte)(key[p % key.Length] ^ (p + loff));
return b;
}
public override void WriteByte(byte value)
{
long p = Position;
byte b = value;
b ^= (byte)(key[p % key.Length] ^ (p + loff));
base.WriteByte(b);
}
#endregion
}
}
Hatte mich mal damit beschäftigt.. Hab hier noch einen namespace gefunden mit zwei statischen Klassen. Sollten eigentlich verständlich sein, sind zwar etwas alt und nicht Kommentiert aber wenn interesse daran besteht ließe sich das ja überarbeiten.
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Threading;
namespace System.FakeInput
{
public static class Mouse
{
[DllImport("user32.dll")]
static extern bool SetCursorPos(int X, int Y);
[DllImport("user32.dll", SetLastError = true)]
private static extern int SendInput(int cInputs, ref INPUT pInputs, int cbSize);
public enum MouseButtons
{
Left,
Right,
Middle
}
const int INPUT_MOUSE = 0;
private struct INPUT
{
public int dwType;
public int Mousedx;
public int Mousedy;
public int MousemouseData;
public int MousedwFlags;
public int Mousetime;
public IntPtr MousedwExtraInfo;
}
const int MOUSEEVENTF_LEFTDOWN = 2;
const int MOUSEEVENTF_LEFTUP = 4;
const int MOUSEEVENTF_MIDDLEDOWN = 32;
const int MOUSEEVENTF_MIDDLEUP = 64;
const int MOUSEEVENTF_MOVE = 1;
const int MOUSEEVENTF_ABSOLUTE = 32768;
const int MOUSEEVENTF_RIGHTDOWN = 8;
const int MOUSEEVENTF_RIGHTUP = 16;
private static void MouseClick(int x, int y, int MouseButton)
{
//Constructing Inputdata
INPUT inputevents = new INPUT();
inputevents.Mousedx = 0;
inputevents.Mousedy = 0;
inputevents.MousemouseData = 0;
inputevents.MousedwFlags = MouseButton;
inputevents.Mousetime = 0;
inputevents.dwType = INPUT_MOUSE;
int cbSize = Marshal.SizeOf(typeof(INPUT));
//Sending Input
SetCursorPos(x, y); //Setting Mouseposition
int result = SendInput(1, ref inputevents, cbSize); //"Performing Click"
}
public static void doMouseClick(int x, int y, MouseButtons MouseButton)
{
switch (MouseButton)
{
case MouseButtons.Left:
MouseClick(x, y, MOUSEEVENTF_LEFTDOWN);
MouseClick(x, y, MOUSEEVENTF_LEFTUP);
break;
case MouseButtons.Middle:
MouseClick(x, y, MOUSEEVENTF_MIDDLEDOWN);
MouseClick(x, y, MOUSEEVENTF_MIDDLEUP);
break;
case MouseButtons.Right:
MouseClick(x, y, MOUSEEVENTF_RIGHTDOWN);
MouseClick(x, y, MOUSEEVENTF_RIGHTUP);
break;
default:
break;
}
}
}
public static class Keyboard
{
[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
public static extern void keybd_event(
byte bVk,
byte bScan,
int dwFlags,
int dwExtraInfo
);
[DllImport("USER32.DLL")]
public static extern IntPtr FindWindow(
string lpszClass, // class name
string lpszWindow // window name
);
[DllImport("User32.dll", SetLastError = true)]
public static extern int SendInput(int nInputs, ref INPUT pInputs, int cbSize);
public struct KEYBDINPUT
{
public ushort wVk;
public ushort wScan;
public uint dwFlags;
public long time;
public uint dwExtraInfo;
};
[StructLayout(LayoutKind.Explicit, Size = 28)]
public struct INPUT
{
[FieldOffset(0)]
public uint type;
[FieldOffset(4)]
public KEYBDINPUT ki;
};
private class VKData
{
public int Timeout;
public byte VirtualKey;
public VKData()
{
this.Timeout = 0;
this.VirtualKey = 0;
}
}
public enum VK : byte
{
SPACE = 0x20,
SHIFT = 0x10,
CONTROL = 0x11,
MENU = 0x12,
ESCAPE = 0x1B,
BACK = 0x08,
TAB = 0x09,
RETURN = 0x0D,
PRIOR = 0x21,
NEXT = 0x22,
END = 0x23,
HOME = 0x24,
LEFT = 0x25,
UP = 0x26,
RIGHT = 0x27,
DOWN = 0x28,
SELECT = 0x29,
PRINT = 0x2A,
EXECUTE = 0x2B,
SNAPSHOT = 0x2C,
INSERT = 0x2D,
DELETE = 0x2E,
HELP = 0x2F,
NUMPAD0 = 0x60,
NUMPAD1 = 0x61,
NUMPAD2 = 0x62,
NUMPAD3 = 0x63,
NUMPAD4 = 0x64,
NUMPAD5 = 0x65,
NUMPAD6 = 0x66,
NUMPAD7 = 0x67,
NUMPAD8 = 0x68,
NUMPAD9 = 0x69,
MULTIPLY = 0x6A,
ADD = 0x6B,
SEPARATOR = 0x6C,
SUBTRACT = 0x6D,
DECIMAL = 0x6E,
DIVIDE = 0x6F,
F1 = 0x70,
F2 = 0x71,
F3 = 0x72,
F4 = 0x73,
F5 = 0x74,
F6 = 0x75,
F7 = 0x76,
F8 = 0x77,
F9 = 0x78,
F10 = 0x79,
F11 = 0x7A,
F12 = 0x7B,
OEM_1 = 0xBA, // ',:' for US
OEM_PLUS = 0xBB, // '+' any country
OEM_COMMA = 0xBC, // ',' any country
OEM_MINUS = 0xBD, // '-' any country
OEM_PERIOD = 0xBE, // '.' any country
OEM_2 = 0xBF, // '/?' for US
OEM_3 = 0xC0, // '`~' for US
MEDIA_NEXT_TRACK = 0xB0,
MEDIA_PREV_TRACK = 0xB1,
MEDIA_STOP = 0xB2,
MEDIA_PLAY_PAUSE = 0xB3,
LWIN = 0x5B,
RWIN = 0x5C
}
public const int KEYEVENTF_EXTENDEDKEY = 0x01;
public const int KEYEVENTF_KEYUP = 0x02;
public static void Test()
{
Mouse.doMouseClick(674, 1007, Mouse.MouseButtons.Left);
Thread.CurrentThread.Join(5000);
int intReturn = 0;
INPUT structInput;
structInput = new INPUT();
structInput.type = (uint)1;
structInput.ki.wScan = 0;
structInput.ki.time = 0;
structInput.ki.dwFlags = 0;
structInput.ki.dwExtraInfo = 0;
// Key down the actual key-code
structInput.ki.wVk = 0x10;//"Q".ToCharArray()[0];//vk;
intReturn = SendInput(1, ref structInput, Marshal.SizeOf(structInput));
Thread.CurrentThread.Join(3000);
// Key up the actual key-code
structInput.ki.dwFlags = KEYEVENTF_KEYUP;
structInput.ki.wVk = 0x10;//"Q".ToCharArray()[0];//vk;
intReturn = SendInput(1, ref structInput, Marshal.SizeOf(structInput));
}
public static void writeNumbersAndChars(string s)
{
char[] chars = s.ToCharArray();
foreach (char c in chars)
{
if (char.IsWhiteSpace(c)) //Leerzeichen
{
keybd_event((byte)VK.SPACE, 0x45, 0, 0);
keybd_event((byte)VK.SPACE, 0x45, KEYEVENTF_KEYUP, 0);
}
if (char.IsUpper(c)) //Hochgestellte
{
keybd_event((byte)VK.SHIFT, 0x45, 0, 0);
keybd_event((byte)c, 0x45, 0, 0);
keybd_event((byte)c, 0x45, KEYEVENTF_KEYUP, 0);
keybd_event((byte)VK.SHIFT, 0x45, KEYEVENTF_KEYUP, 0);
}
if (char.IsLower(c)) //Normal
{
char ctu = char.ToUpper(c);
keybd_event((byte)ctu, 0x45, 0, 0);
keybd_event((byte)ctu, 0x45, KEYEVENTF_KEYUP, 0);
}
if (char.IsNumber(c)) //Zahlen
{
keybd_event((byte)c, 0x45, 0, 0);
keybd_event((byte)c, 0x45, KEYEVENTF_KEYUP, 0);
}
}
}
public static void writeNumbersAndCharsHuman(string s)
{
char[] chars = s.ToCharArray();
Random rndm = new Random();
foreach (char c in chars)
{
if (char.IsWhiteSpace(c)) //Leerzeichen
{
keybd_event((byte)VK.SPACE, 0x45, 0, 0);
keybd_event((byte)VK.SPACE, 0x45, KEYEVENTF_KEYUP, 0);
Thread.CurrentThread.Join(rndm.Next(50, 150));
}
if (char.IsUpper(c)) //Hochgestellte
{
keybd_event((byte)VK.SHIFT, 0x45, 0, 0);
keybd_event((byte)c, 0x45, 0, 0);
keybd_event((byte)c, 0x45, KEYEVENTF_KEYUP, 0);
Thread.CurrentThread.Join(rndm.Next(50, 300));
keybd_event((byte)VK.SHIFT, 0x45, KEYEVENTF_KEYUP, 0);
}
if (char.IsLower(c)) //Normal
{
char ctu = char.ToUpper(c);
keybd_event((byte)ctu, 0x45, 0, 0);
keybd_event((byte)ctu, 0x45, KEYEVENTF_KEYUP, 0);
Thread.CurrentThread.Join(rndm.Next(50, 300));
}
if (char.IsNumber(c)) //Zahlen
{
keybd_event((byte)c, 0x45, 0, 0);
keybd_event((byte)c, 0x45, KEYEVENTF_KEYUP, 0);
Thread.CurrentThread.Join(rndm.Next(50, 300));
}
}
}
public static void doKeypress(byte VirtualKey)
{
keybd_event(VirtualKey, 0x45, 0, 0);
keybd_event(VirtualKey, 0x45, KEYEVENTF_KEYUP, 0);
}
public static void doKeypress(byte VirtualKey, int Timeout)
{
KeypressTimeoutThread = new Thread(KeypressTimeout);
VKData data = new VKData();
data.VirtualKey = VirtualKey;
data.Timeout = Timeout;
KeypressTimeoutThread.Start(data);
}
private static Thread KeypressTimeoutThread;
private static void KeypressTimeout(object Data)
{
VKData vkData = (VKData)Data;
keybd_event(vkData.VirtualKey, 0x45, KEYEVENTF_EXTENDEDKEY, 0);
}
}
}
Da hab ich natürlich schon reingeguckt. Es flackert auch nur das selektierte Item alles andere wird komplett "flüssig" gezeichnet. Man sieht das auch seh schön wenn man einfach Arrow-Down gedrückt hält wärend die LB den fokus hat... ich teste das jetzt gleich mal an einer anderen LB.
Ich hab mich hier an einem bitweisen vergleich zweier Images versucht. Mein Problem ist nur das die Strides beider Bilder negativ sind (deswegen auch Math.Abs()). Wenn man versucht den Speicher zu kopieren erhält man beim zweiten Schritt eine Zugriffsverletzung. Nun komm ich nicht weiter, ich hab keine Ahnung woher die Zugriffsverletzung kommt.
public static bool SameAs(this Image g, Image img)
{
#region VALUE_COMPARE
#if VALUE_COMPARE
if (g.Width != img.Width || g.Height != img.Height)
return false;
if (g.HorizontalResolution != img.HorizontalResolution)
return false;
if (g.VerticalResolution != img.VerticalResolution)
return false;
if (g.PixelFormat != img.PixelFormat)
return false;
if (g.Palette.Flags != img.Palette.Flags)
return false;
if (g.Flags != img.Flags)
return false;
#endif
#endregion
#region BIT_COMPARE
#if BIT_COMPARE
// Bit compare
Bitmap one = g as Bitmap;
Bitmap two = img as Bitmap;
BitmapData d0 = one.LockBits(new Rectangle(0, 0, one.Width, one.Height), ImageLockMode.WriteOnly, one.PixelFormat);
BitmapData d1 = two.LockBits(new Rectangle(0, 0, two.Width, two.Height), ImageLockMode.WriteOnly, two.PixelFormat);
int s0 = Math.Abs(d0.Stride);
int s1 = Math.Abs(d1.Stride);
/* I think this cannot happen if VALUE_COMPARE is defined. */
bool retval = false;
if (s0 != s1)
goto finalize;
if (d0.Stride != d1.Stride)
goto finalize;
IntPtr scan0 = d0.Scan0;
IntPtr scan1 = d1.Scan0;
for (int i = 0; i < one.Height; i++)
{
byte[] b0 = new byte[s0];
byte[] b1 = new byte[s0];
Marshal.Copy(scan0, b0, i * s0, s0);
Marshal.Copy(scan1, b1, i * s0, s0);
for (int j = 0; j < s0; j++)
{
if (b0[j] != b1[j])
{
goto finalize;
}
}
}
retval = true;
finalize:
one.UnlockBits(d0);
two.UnlockBits(d1);
return retval;
#else
return true;
#endif
#endregion
}
ich hab eine Listbox in deren OnDrawItem-Ereigniss ich die Items zeichne. Soweit so gut, nur ist mir aufgefallen, dass das selektierte Item, wärend der Laufzeit, flackert. Sehr gut zu beobachten ist dies wenn ganz nach unten scrollt und man nicht mehr weiter scrollen kann das selektierte Item noch sichtbar ist und trozdem weiter nach unten scrollt (mit dem Mausrad). AllPaintingInWmPaint ist gesetzt und OptimizedDoubleBuffer auch. Kann jemand dieses Verhalten bestätigen? Hat das jemand vllt schon beobachtet? Ist da vllt was zu machen?
Hier mal ein grobes Beispiel:
protected override void OnDrawItem(DrawItemEventArgs e)
{
Pen p = new Pen(Color.Transparent);
SolidBrush b = new SolidBrush(Color.Transparent);
Graphics dc = e.Graphics;
dc.CompositingQuality = CompositingQuality.HighSpeed;
dc.InterpolationMode = InterpolationMode.HighQualityBicubic;
dc.SmoothingMode = SmoothingMode.HighQuality;
dc.SetColorTableWindowsVista(_clTable);
dc.FillRectangle(new SolidBrush(BackColor), e.Bounds);
dc.DrawVistaButtonBackground(e.Bounds, 2,
true,
false,
(e.State & DrawItemState.Selected) == DrawItemState.Selected
/*(e.State & DrawItemState.Focus) == DrawItemState.Focus*/);
FileData fd = null;
if (e.Index > -1 && e.Index < Items.Count)
fd = Items[e.Index] as FileData;
if (fd != null)
{
if (fd.FileIco != null)
dc.DrawIcon(fd.FileIco, new Rectangle(e.Bounds.Left + 2, e.Bounds.Top + 2, 35, 35));
SizeF sz = dc.MeasureString(fd.FileName, e.Font);
RectangleF rc = new RectangleF(
e.Bounds.Left + 37,
e.Bounds.Top + 5,
e.Bounds.Width - 5,
sz.Height);
StringFormat sf = new StringFormat();
sf.FormatFlags = StringFormatFlags.NoWrap;
sf.Trimming = StringTrimming.EllipsisCharacter;
dc.DrawString(fd.FileName, e.Font, Brushes.White, rc, sf);
sz = dc.MeasureString(fd.FileName, e.Font);
rc = new RectangleF(
e.Bounds.Left + 37,
e.Bounds.Bottom - sz.Height + 2,
e.Bounds.Width - 40,
sz.Height);
sf = new StringFormat();
sf.FormatFlags = StringFormatFlags.NoWrap;
sf.Trimming = StringTrimming.EllipsisPath;
dc.DrawString(fd.File, new Font(e.Font.FontFamily, 6), new SolidBrush(Color.FromArgb(100, 255, 255, 255)),
rc, sf);
}
}
So hier nochmal eine vernünftige funktion zur Lösung des Problems:
/// <summary>
/// Berechnet anhand eines gegebenen Winkels (a) und des Radius (r)
/// einen von [0, 0] ausgehenden Vector.
/// </summary>
/// <param name="a"> Winkel. </param>
/// <param name="r"> Radius. </param>
/// <returns>Der Vector.</returns>
private PointF AngleToPosition(double a, double r)
{
// Bogenmaß des Winkels errechnen
a *= (Math.PI / 180);
// Kosinus des Winkels a
double cos = Math.Cos(a);
// Sinus des Winkels a
double sin = Math.Sin(a);
// Der Vector
PointF B = new PointF();
B.X = (float)(cos * r);
B.Y = (float)(sin * r);
return B;
}
Anwendungsbeispiel:
Wie man auf dem von mir angehängten Bild erkennen kann zeigen zwei Linien auf die Mittelpunkte der Kreisdiagrammteile. Um diese Mittelpunkte zu errechnen wird die obige funktion mit der hälfte des Winkels des einen Kreisdiagrammteil und dessen Radius * .75f aufgerufen. Der daraus resultierende Vektor wird mit dem Mittelpunkt des Kreisdiagrammes einfach addiert. Eviolá.
Hab mir das ganze mal angeschaut und folgendes ist dabei herumgekommen:
private PointF PosFrom(double ang, double radius)
{
if (ang < 0 || ang > 360)
throw new Exception("ang have to be between 0 - 360.");
double fcos = 1;
double fsin = 1;
/* ± sin± cos± tan± cot±
* 1. Quadrant 0–90° + + + +
* 2. Quadrant 90–180° +
* 3. Quadrant 180–270° + +
* 4. Quadrant 270–360° +
*/
if (ang < 90)
{
fcos = 1;
fsin = 1;
}
else if (ang < 180)
{
fcos = -1;
fsin = 1;
}
else if (ang < 270)
{
fcos = -1;
fsin = -1;
}
else if (ang < 360)
{
fcos = 1;
fsin = -1;
}
double cos = Math.Cos(ang);
double sin = Math.Sin(ang);
PointF B = new PointF();
B.X = (float)(cos * radius * fcos);
B.Y = (float)(sin * radius * fsin);
return B;
}
Funktioniert aber nicht so wirklich irgendwas mach ich wohl noch falsch jemand ne idee?
[EDIT] Math.Cos sowie Math.Sin und Math.Tan erwarten Bogenmaß omfg... da hab ich jetzt dran geschraubt... is mir beim debuggen aufgefallen cos war bei nem wert von 90 nicht 0 ich dacht ich fall vom glauben ab... xD
Ich weiß nict genau wie ich mich jetzt ausdrücken soll aber ich möchte gerne einen Vector anhand eines Winkel und einem Radius errechnen. Ist das irgendwie möglich? Bin nicht so das Mathegenie wüsste auch nicht wie ich sowas Suchen sollte...
Ich möchte nämlich ein Kreisdiagramm zeichnen und mittels Pfeilen auf dessen Teilstücke zeigen.