Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将“窗体边框样式”更改为“无”,在使用线性渐变笔刷时会导致错误_C#_Forms_Border_Linear Gradients - Fatal编程技术网

C# 将“窗体边框样式”更改为“无”,在使用线性渐变笔刷时会导致错误

C# 将“窗体边框样式”更改为“无”,在使用线性渐变笔刷时会导致错误,c#,forms,border,linear-gradients,C#,Forms,Border,Linear Gradients,我的Windows窗体应用程序有问题。我必须更改配置以处理访问冲突异常 不管怎样,我基本上是在制作一个程序,它会像通知一样出现在右下角。这不是整个计划,而是我将要整合的东西。我对LinearGradientBrush类有一些问题。我注意到我的窗口在试图通过AccessViolationException绘制背景时正在移动,因此我在OnPaintBackground方法中创建了一个布尔值,以记录绘制过程的时间,并确保在函数运行时窗口不会移动。这似乎解决了问题。除此之外,当我通过在FormBorde

我的Windows窗体应用程序有问题。我必须更改配置以处理访问冲突异常

不管怎样,我基本上是在制作一个程序,它会像通知一样出现在右下角。这不是整个计划,而是我将要整合的东西。我对LinearGradientBrush类有一些问题。我注意到我的窗口在试图通过AccessViolationException绘制背景时正在移动,因此我在OnPaintBackground方法中创建了一个布尔值,以记录绘制过程的时间,并确保在函数运行时窗口不会移动。这似乎解决了问题。除此之外,当我通过在FormBorderStyle面板中去掉边框来进一步定制表单设计时,问题返回。我不知道为什么这会引起任何麻烦,我到处寻找解决办法,但都没有结果。非常感谢您的帮助。多谢各位

 <configuration>
 <startup> 
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
 </startup>
 <runtime>
  <legacyCorruptedStateExceptionsPolicy enabled="true" />
 </runtime>
 </configuration>


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

 namespace NewToasterNotifier
{
public partial class Form1 : Form
{
    private Timer timer;
    private int startPosX, startPosY, beginning, middle, speed, paintCount;
    private bool rectangleIsDrawing;
    public Form1()
    {
        InitializeComponent();
        TopMost = true;
        ShowInTaskbar = false;

        timer = new Timer();
        timer.Interval = 20;

        timer.Tick += timer_Tick;
        //This divides the window into three sections
        //The beginning is first used as the scalar amaount of each interval
        beginning = Height / 3;
        //middle is where the middle section ends
        middle = Screen.PrimaryScreen.WorkingArea.Height - 2 * beginning;
        //and now beginnning is where the beginning section ends
        //the true begginnning section starts at the screen.height
        beginning = Screen.PrimaryScreen.WorkingArea.Height - beginning;
        speed = 0;
    }
    //On load of the form
    protected override void OnLoad(EventArgs e)
    {
        startPosX = Screen.PrimaryScreen.WorkingArea.Width - Width;
        startPosY = Screen.PrimaryScreen.WorkingArea.Height;
        SetDesktopLocation(startPosX, startPosY);
        base.OnLoad(e);
        timer.Start();
        paintCount = 0;
    }
    //Override of the onPaintbackground, which allows us to make a different background on windows forms
    protected override void OnPaintBackground(PaintEventArgs e)
    {
        rectangleIsDrawing = true;
        paintCount++;
        Console.Write("\n Painting... " + paintCount.ToString());
        //implements a linear gradient to the background
        using (LinearGradientBrush brush = new LinearGradientBrush(this.ClientRectangle,
                                                          Color.Gray,
                                                          Color.Black,
                                                          90F))
        {
            paintThatShiz(e, brush);
        }
    }
    //linear gradient needs to change on resize
    protected override void OnResize(EventArgs e)
    {
        this.Invalidate();
        base.OnResize(e);
    }
    //debugging purposes
    private void paintThatShiz(PaintEventArgs e, LinearGradientBrush brush)
    {


        try { e.Graphics.FillRectangle(brush, this.ClientRectangle); }
        catch (AccessViolationException x)
        {
            Console.Write("No, no, no!!!!!");
            paintThatShiz(e, brush);
        }
        catch (InvalidOperationException z)
        {
            Console.Write("This is ridiculous, \n");
            Console.Write(z.StackTrace);
            paintThatShiz(e, brush);
        }
        rectangleIsDrawing = false;

    }
    //called every 10ms for window to animate and stops when done
    void timer_Tick(object sender, EventArgs e)
    {
        if (rectangleIsDrawing) { return; }

        Console.Write("\n Starting to move");
        // this if block is for the swing animation
        //in the beginning it speeds up
        if (startPosY > beginning)
        {
            speed++;
        }//in the end it slows down
        else if (startPosY < middle)
        {
            if (speed > 1)
            {
                speed--;
            }
        }
        //in the middle it stays constant
        Console.Write(speed.ToString() + " ");
        startPosY -= speed;
        //Stops when done
        if (startPosY < Screen.PrimaryScreen.WorkingArea.Height - Height)
        {
            timer.Stop();
        } // checks again to see if rectangle is drawing before accessing window location data
        else {
            if (rectangleIsDrawing) {
                startPosY += speed;
                return; 
            }
            SetDesktopLocation(startPosX, startPosY);
        }



    }


}

使用制度;
使用System.Collections.Generic;
使用系统组件模型;
使用系统数据;
使用系统图;
使用System.Drawing.Drawing2D;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
使用System.Windows.Forms;
名称空间NewToasterNotifier
{
公共部分类Form1:Form
{
私人定时器;
私有int startPosX,startPosY,开始,中间,速度,paintCount;
私有布尔矩形绘制;
公共表格1()
{
初始化组件();
最顶端=真;
ShowInTaskbar=false;
定时器=新定时器();
时间间隔=20;
timer.Tick+=定时器_Tick;
//这将窗口分为三个部分
//开始部分首先用作每个间隔的标量计数
开始=高度/3;
//中间是中间部分结束的地方
中间=Screen.PrimaryScreen.WorkingArea.Height-2*开始;
//现在开始是开始部分的结束
//真正的Begginning部分从screen.height开始
开始=Screen.PrimaryScreen.WorkingArea.Height-开始;
速度=0;
}
//装载表格
受保护的覆盖无效加载(事件参数e)
{
startPosX=Screen.PrimaryScreen.WorkingArea.Width-Width;
startPosY=Screen.PrimaryScreen.WorkingArea.Height;
SetDesktopLocation(startPosX、startPosY);
基础荷载(e);
timer.Start();
油漆计数=0;
}
//重写onPaintbackground,它允许我们在windows窗体上创建不同的背景
PaintBackground上受保护的覆盖无效(PaintEventArgs e)
{
矩形绘制=真;
paintCount++;
Console.Write(“\n绘画…”+paintCount.ToString());
//实现到背景的线性渐变
使用(LinearGradientBrush brush=新的LinearGradientBrush(this.ClientRectangle,
颜色,灰色,
颜色,黑色,
(90F)
{
油漆刷(e,刷子);
}
}
//调整大小时需要更改线性渐变
受保护的覆盖void OnResize(事件参数e)
{
这个。使无效();
基数(e);
}
//调试目的
私有虚空painthatshiz(PaintEventArgs e、LinearGradientBrush)
{
试试{e.Graphics.FillRectangle(笔刷,this.ClientRectangle);}
捕获(AccessViolationException x)
{
控制台。写(“不,不,不!!!”;
油漆刷(e,刷子);
}
捕获(无效操作异常z)
{
Console.Write(“这太荒谬了,”);
Console.Write(z.StackTrace);
油漆刷(e,刷子);
}
矩形绘制=假;
}
//每10毫秒调用一次,让窗口设置动画,完成后停止
无效计时器勾号(对象发送方,事件参数e)
{
if(矩形绘制){return;}
Console.Write(“\n开始移动”);
//此if块用于swing动画
//一开始它加速了
如果(开始>开始)
{
速度++;
}//最后它变慢了
否则,如果(起始位置<中间位置)
{
如果(速度>1)
{
速度--;
}
}
//在中间,它保持不变
Console.Write(speed.ToString()+);
startPosY-=速度;
//完成后停止
if(启动OSY

}

终于明白了,不要将Windows窗体用于定制外观的窗口。特别是线性渐变工具,这是一个非常有缺陷的工具,实际上只是一个在窗体顶部绘制矩形的技巧。我开始使用WPF,这很神奇。我并不想吹嘘自己,但我希望这能引导人们避免出于这些原因使用Windows窗体