C# WinForms -Panel schneidet ohne Grund viel zu viel Bedienelemente abC#

Ein Treffpunkt für C#-Programmierer
Anonymous
 C# WinForms -Panel schneidet ohne Grund viel zu viel Bedienelemente ab

Post by Anonymous »

Ich habe ein Panel in einem Formular und dieses Panel befindet sich in einem TABPAGE eines Tabcontrol. Alles ist in Ordnung, auch wenn ich Dinge an der linken Kante einfüge, aber aus irgendeinem Grund sei es ein Fehler in Visual Studio oder im Designer selbst, wenn ich eine Kontrolle platziere, wird in diesem Fall eine selbstgemachte Benutzerkontrolle nicht vollständig erscheint, aber es wird abgeschnitten, so dass nur ein kleiner Teil von ihm sichtbar ist. Der lange Satz XD < /p>
Hier ist ein Screenshot: < /p>
Bild des Ausschnitts < /p>
Hier ist der Code der Benutzersteuerung für alle, die sich fragen: < /p>

Code: Select all

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MessengerApp
{
public partial class ChatMessage :  UserControl
{
string textf = string.Empty;

SizeF stringlänge;
bool gedreht = false;
int num = 0;

public ChatMessage(string texte, int nummer)
{
InitializeComponent();

Size = new Size(500, 500);
num = nummer;
textf = texte;

Graphics g = CreateGraphics();
stringlänge = g.MeasureString(texte, DefaultFont);

Size = new Size((int)stringlänge.Width + 73, (int)stringlänge.Height + 33);
}

private void ChatMessage_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
g.SmoothingMode = SmoothingMode.AntiAlias;

SizeF größe = g.MeasureString(textf, DefaultFont);

Size endgröße = new Size((int)größe.Width + 120, (int)größe.Height + 83);

int f = 0;
int y = (int)größe.Width;

if (gedreht)
{
f = 20;
y = (int)größe.Width + 73;
}

// Hauptrechteck der Sprechblase
RectangleF rect = new RectangleF(1 + f, 1, größe.Width + 50, größe.Height + 30);
float radius = 20f;

Size = new Size(y, (int)rect.Height + 3);

// Zeiger-Einstellungen
bool zeigerLinks = gedreht;// Ändere zu false für rechte Seite
PointF zeigerSpitze;
PointF zeigerOben;
PointF zeigerUnten;

if (zeigerLinks)
{
zeigerSpitze = new PointF(rect.Left - 20, rect.Bottom);
zeigerOben = new PointF(rect.Left, zeigerSpitze.Y - 20);
zeigerUnten = new PointF(rect.Left, zeigerSpitze.Y);
}
else
{
zeigerSpitze = new PointF(rect.Right + 20, rect.Bottom);
zeigerOben = new PointF(rect.Right, zeigerSpitze.Y - 20);
zeigerUnten = new PointF(rect.Right, zeigerSpitze.Y);
}

// Erstelle Pfad mit abgerundetem Rechteck + Zeiger
GraphicsPath path = new GraphicsPath();
float d = radius * 2;

if (zeigerLinks)
{
// Start oben links
path.AddArc(rect.Left, rect.Top, d, d, 180, 90);
path.AddLine(rect.Left + radius, rect.Top, rect.Right - radius, rect.Top);
path.AddArc(rect.Right - d, rect.Top, d, d, 270, 90);
path.AddLine(rect.Right, rect.Top + radius, rect.Right, rect.Bottom - radius);
path.AddArc(rect.Right - d, rect.Bottom - d, d, d, 0, 90);

PointF control = new PointF(zeigerOben.X, zeigerSpitze.Y - 10);
PointF control2 = new PointF(zeigerSpitze.X + 10, zeigerSpitze.Y);
PointF control4 = new PointF(zeigerOben.X - 10.01f, zeigerOben.Y + 10.01f);

path.AddBezier(zeigerSpitze, control4, control, zeigerOben);

//   path.AddLine(zeigerSpitze.X, zeigerSpitze.Y, rect.Left, zeigerOben.Y);
path.AddLine(rect.Left, zeigerOben.Y - 10, rect.Left, rect.Top + radius);
}
else
{
// Start oben links
path.AddArc(rect.Left, rect.Top, d, d, 180, 90);
path.AddLine(rect.Left + radius, rect.Top, rect.Right - radius, rect.Top);
path.AddArc(rect.Right - d, rect.Top, d, d, 270, 90);
path.AddLine(rect.Right, rect.Top + radius, rect.Right, rect.Bottom - radius);
// path.AddLine(rect.Right - radius, rect.Bottom, rect.Left + radius, rect.Bottom);

PointF control = new PointF(zeigerOben.X, zeigerSpitze.Y - 10);
PointF control2 = new PointF(zeigerSpitze.X - 10, zeigerSpitze.Y);
PointF control4 = new PointF(zeigerOben.X + 0.01f, zeigerOben.Y - 0.01f);

path.AddBezier(zeigerOben, control4, control, zeigerSpitze);

path.AddLine(rect.Right - radius, rect.Bottom, rect.Left + radius, rect.Bottom);
path.AddArc(rect.Left, rect.Bottom - d, d, d, 90, 90);

// path.AddLine(zeigerSpitze.X, zeigerSpitze.Y, rect.Left, zeigerOben.Y);
// path.AddLine(rect.Left, rect.Bottom - 10, rect.Left,  rect.Top + radius);
}

path.CloseFigure();

// Füllen
using (Brush b = new SolidBrush(Color.LightBlue))
{
g.FillPath(b, path);
}

// Umriss
using (Pen p = new Pen(Color.DarkBlue, 2))
{
g.DrawPath(p, path);
}

// Text
string text = textf;

using (Font font = new Font("Segoe UI", 10))
using (Brush tb = new SolidBrush(Color.Black))
{
RectangleF textRect = rect;
g.DrawString(text, font, tb, textRect, new StringFormat
{
Alignment = StringAlignment.Center,
LineAlignment = StringAlignment.Center
});
}
}

public int number
{
get
{
return num;
}
}

public bool drehen
{
get
{
return gedreht;
}
set
{
gedreht = value;
}
}
}
}
< /code>
Und hier ist der Abschnitt, in dem das Steuerelement zum Bedienfeld hinzugefügt wird. < /p>
foreach ((int, string, string) strings in ns.GetList)
{
if (!panel1.Controls.OfType().Any(x => x.number == strings.Item1))
{
ChatMessage chat = new ChatMessage(strings.Item3, strings.Item1);

i += 20;
int x = 0;

if (strings.Item2 != Name)
{
chat.drehen = true;
}
else
{
chat.drehen = false;
x = panel1.Width - chat.Width;
}

if (panel1.Controls.Count == 0)
chat.Location = new Point(x, 0);
else
chat.Location = new Point(x, panel1.Controls.OfType().Last().Location.Y + panel1.Controls.OfType().Last().Size.Height + 10);

panel1.Controls.Add(chat);
}
}

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post