Tag: paint

C#Invalidate不调用paint方法

我有OnPaint方法覆盖在屏幕上绘制一个椭圆。 protected override void OnPaint(PaintEventArgs e) { MessageBox.Show(“Paint”); if (debugStarted) { int y = rtbLogicCode.PlaceToPoint(new Place(0, debugLine)).Y; if (rtbLogicCode.GetVisibleState(debugLine).ToString() == “Visible”) { e.Graphics.FillEllipse(new LinearGradientBrush(new Rectangle(0, y, 15, 15), Color.LightPink, Color.Red, 45), 0, y, 15, 15); } base.OnPaint(e); } } private void rtbLogicCode_Scroll(object sender, ScrollEventArgs e) { this.Invalidate(); } 滚动事件(在Richtextbox上)被正确处理,但即使我使表单无效,它也没有调用OnPaint函数(消息框未显示)。 可能的原因是什么? 编辑:我忘了提到我的子窗体的初始化函数(使用MDI属性添加为主窗体的控件),我设置以下样式: private void LogicCodeInit() { […]

WPF应用程序内WinForms控件上的自定义绘制处理程序

我有一个WPF应用程序,其中包含一个Windows窗体元素,使用此方法: System.Windows.Forms.Integration.WindowsFormsHost host = new System.Windows.Forms.Integration.WindowsFormsHost(); gMapZoom = new GMap(); gMapZoom.Paint += new PaintEventHandler(gMapZoom_Paint); host.Child = gMapZoom; // gMapZoom is the Windows Form control // Add the interop host control to the Grid // control’s collection of child controls. this.grid1.Children.Add(host); 但是,我在尝试向其添加自定义Paint事件处理程序时遇到问题。 似乎在WPF中添加它(此处未显示)会导致绘图在WinForm控件下完成,因此顶部没有任何内容。 将它添加到WinForm控件不会做任何事情; 甚至从未调用paint事件(gMapZoom_Paint)。 任何帮助将非常感激。

Unity3D在C#中寻找使用纹理绘制的setPixels示例

我需要找到一种方法,允许我使用纹理绘制一个gameObject,目标是克隆这个游戏 我已经认为我可以通过使用我在这里解释的depthMask解决方案伪造绘画function,但是,经过数小时的研究后,似乎可以使用setPixels,setPixel和setPixels32来创建真实的绘画,但由于某种原因所有的setPixels都相关脚本参考的主题是在JavaScript中,我试图将它移植到c#,但我总是有错误,加上它是一种复杂的方法,脚本参考不能很好地解释它,所以我希望有人可以请我写信给我使用setPixels来使用另一个纹理更改对象纹理的一部分的示例? 或者我们可以将整个对象alpha设置为0,当我们点击它时,我们将该纹理alpha的一部分更改为1? 我真的希望这个话题不会因为它的多样性而被关闭,我尽力在解释整个情况时提出一个直截了当的问题。 谢谢 编辑: 几个小时之后,我已经达到了一个非常酷的结果,我认为这可能是达到我的目标的好方法,这个脚本允许用另一个选择的纹理替换材质纹理中的特定像素(目标纹理必须大小相同,可读) // the texture that i will paint with public Texture2D targetTexture ; //temporary texture Texture2D tmpTexture; void Start () { //setting temp texture width and height tmpTexture = new Texture2D (targetTexture.width, targetTexture.height); for (int y =0; y<tmpTexture.height; y++) { for (int x = 0; x<tmpTexture.width; x++) { //filling […]

为什么我的图像不会移动?

我正在制作一个2D自上而下的游戏,玩家控制着一只猫。 为此,此人使用WASD键移动。 我有Form1,GameManager,Cat和Moveable类。 Form1向GameManager发送cat imagelist和e.graphics(用于图片框)。 GameManager有一个计时器,每个勾选检查猫是否已经移动。 Cat处理移动逻辑。 当我运行程序时,cat精灵显示在其初始位置,但是在按下键时不会移动。 我无法弄清楚我的问题,有人可以帮忙吗? 这是我的课程: Form1中: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace CatAndMouse { public partial class Form1 : Form { GameManager myGM = new GameManager(); public Form1() { InitializeComponent(); newGame(); } private void pictureBox1_Paint(object sender, PaintEventArgs e) { […]

在我的Paint程序中绘制矩形时出错

public partial class Form1 : Form { Point downPoint , upPoint; List shapes = new List(); public ShapesEnum shapeType; public Form1() { InitializeComponent(); } protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); foreach (var s in shapes) s.Draw(e.Graphics); } protected override void OnMouseDown(MouseEventArgs e) { downPoint = e.Location; } protected override void OnMouseUp(MouseEventArgs e) { base.OnMouseUp(e); […]

无法在c#中的表单加载上绘制椭圆

我试图在c#中的formload上包含PNG的图片框中绘制一些椭圆。 当我执行下面的代码时,我看到我的省略号半秒钟,然后我不再看到它们了。 当我点击我的图片框时,我能够绘制一个椭圆,但是当我最小化表格时,它们不再出现。 我已经读过你不应该把你的绘图代码放在formload中,而应该放在OnPaint方法中,这就是我所做的。 我不知道该怎么办了。 谢谢。 (请注意,我已经留下了一些代码,以显示我尝试过的内容)。 public partial class FormParterre : Form { Graphics g; float circleSize = 15; //Brushes rouge = new Brushes (Brushes.Red); ReservationBilletSiegeDAO reservationBilletSiegeDAO = new ReservationBilletSiegeDAO(); SiegeDAO siegeDAO = new SiegeDAO(); List sieges; List rbs; ReservationBillet reservationBillet = new ReservationBillet(); ReservationBilletSiege reservationBilletSiege; SolidBrush semiTransBrush; public FormParterre() { InitializeComponent(); pictureBox1.Image = […]

防止WPF窗口闪烁

我有一个无边框的WPF窗口,需要能够隐藏其中一个控件并同时缩小窗口。 问题是它看起来很糟糕。 这就是我现在正在做的事情: private void btnShowHideTopBar_Click(object sender, RoutedEventArgs e) { if (commandTopHide == true) { txtblkShowHideTopBar.Text = “Show Top Bar”; commandTopHide = false; myWindow.Left = 1100; myWindow.Width = 180; RSide.Width = new GridLength(0, GridUnitType.Pixel); } else if (commandTopHide == false) { txtblkShowHideTopBar.Text = “Hide Top Bar”; commandTopHide = true; myWindow.Left = 1030; myWindow.Width = 250; […]