我正在嘗試製作繪圖應用程序。我創建了一個調用FolderBrowserDialog的函數,它可以工作。現在,我的問題是當試圖使用的地方設置一個.bmp文件我得到「的路徑是一個法律形式不是」繼承人的代碼我無法使用FolderBrowserDialog設置位圖
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace Paint_AppLication
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private bool mouse_down = false;
static string folderPath = "";
private Color col = Color.Black;
private void panel1_MouseDown(object sender, MouseEventArgs e)
{
mouse_down = true;
}
private void panel1_MouseUp(object sender, MouseEventArgs e)
{
mouse_down = false;
}
private void panel1_MouseMove(object sender, MouseEventArgs e)
{
toolStripStatusLabel1.Text = e.X + ", " + e.Y;
if(mouse_down == true)
{
bit = new Bitmap(bit, panel1.Size);
panel1.BackgroundImage = bit;
bit.SetPixel(e.X, e.Y, col);
}
}
private void button1_Click(object sender, EventArgs e)
{
colorDialog1.ShowDialog();
col = colorDialog1.Color;
}
private void Form1_Load(object sender, EventArgs e)
{
FolderBrowserDialog directchoosedlg = new FolderBrowserDialog();
if (directchoosedlg.ShowDialog() == DialogResult.OK)
{
folderPath = directchoosedlg.SelectedPath;
}
}
//My Error Is here
private Bitmap bit = new Bitmap(folderPath);
}
}
您爲每個MouseMove事件創建一個新的位圖?這是非常低效的。 –
@ScottChamberlain我想我會這樣做的,所以它幾乎立即更新面板,但是我該如何解決我目前遇到的錯誤?我如何讓它更有效率,因爲我明白它的效率並不高,謝謝! –
嗯,只是畫'位'而不是每次都做一個新的。基本上離開該功能的代碼相同,但擺脫位=新位圖(位,panel1.Size);' –