Tag: 用户界面

在线程中访问UI

当我尝试更改UI属性(特别是启用)时,我的线程抛出System.Threading.ThreadAbortException 我如何访问线程中的UI。

MessageBox.Show()是否自动编组到UI线程?

我通过ThreadPool.QueueUserWorkItem启动一个线程,其中有一个消息框对话框: System.Windows.Forms.DialogResult dr = System.Windows.Forms.MessageBox.Show(“你想在后台下载升级吗?..”,“升级可用”,MessageBoxButtons.YesNo); 它看起来工作正常,但是在一些客户建议他们没有收到消息后我有点怀疑。 我有.NET Framework 2.0+的感觉你不需要编组这个特定的调用,它会为你做。 正确? 这是一个感兴趣的半相关主题: 为什么在MessageBox.Show中使用所有者窗口?

如何在C#中拖动和移动形状

在C#WindoeFormsApplication中,是否可以选择,因此可以使用鼠标移动或删除绘制的形状? 喜欢windows paint程序。 形状绘图完全正常,所有点都存储在一些数组中。 如此线描示例 Point Latest { get; set; } List _points = new List(); protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); // Save the mouse coordinates Latest = new Point(eX, eY); // Force to invalidate the form client area and immediately redraw itself. Refresh(); } protected override void OnPaint(PaintEventArgs e) { var g […]

多个UI线程 – Winforms

我想在我的应用程序中创建多个UI线程。 我已经模拟了如下方案。 我在后台线程中单击按钮创建一个新窗口/表单 namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { var thread = new Thread(() => { Form f = new Form(); Application.Run(f); }); // thread.IsBackground = true; — Not required. See Solution below thread.SetApartmentState(ApartmentState.STA); thread.Start(); } } } 请注意 […]

如何使用WPF中的Frame控件进行过渡效果?

我觉得这很容易,但我猜不是。 我有两页加载到我的帧控件中。 我希望能够从一个页面到下一个页面具有漂亮的幻灯片效果,或者只是一个简单的淡入效果。 似乎无法在互联网上的任何地方找到它。 更新1接受的答案很好,但我在这里找到了更好的答案。 http://www.japf.fr/2008/07/8/comment-page-1/ 更新2如果您相信它我找到了更好的解决方案。 http://fluidkit.codeplex.com/

如何创建一个hover的C#Winforms控件

如何创建一个超出其区域范围的C#Winforms控件? 比如一个下拉框。 有点像你在小尺寸面板中有一个DropDownBox。

使用Timer在C#中更新UI

我正在努力使我的应用程序从串行端口读取数据并更新UI上的仪表更高效,我想要求我处理UI更改的代码的一些建议。 我有一个定时器设置来检查发送到COM端口的数据和另一个定时器,它使用从COM端口接收的变量更新UI。 基本上发生的事情是我正在旋转仪表。 这是我处理图形的代码…… void timer_Tick(object sender, EventArgs e) //Timer regulates how often the gauge is updated on the UI { if (pictureBox1.Image != null) pictureBox1.Image.Dispose(); // dispose old image (you might consider reusing it rather than making a new one each frame) Point test = new Point((int)_xCor, (int)_yCor); Image img = new Bitmap(400, 400); […]

启动流程的服务不会显示GUI C#

嘿,我正在尝试获得一项服务来启动我的程序,但它没有显示GUI。 该过程开始但没有显示任何内容。 我尝试启用“允许服务与桌面交互”,但仍然无效。 我的程序是一个计算机锁定设备,用于阻止未经授权的用户访问计算机。 我正在运行带有64位操作系统的Windows 7。 这是我服务的代码: protected override void OnStart(string[] args) { Process p = new Process(); p.StartInfo.FileName = “notepad.exe”; p.Start(); FileStream fs = new FileStream(@”C:\Users\David\Documents\Visual Studio 2010\Projects\LockPCService\LockPCService\bin\Debug\ServiceLog.dj”, FileMode.OpenOrCreate, FileAccess.Write); StreamWriter m_streamWriter = new StreamWriter(fs); m_streamWriter.BaseStream.Seek(0, SeekOrigin.End); m_streamWriter.WriteLine(” LockPCService: Service Started ” + DateTime.Now + “\n” + “\n”); m_streamWriter.Flush(); m_streamWriter.Close(); } protected override void […]

为什么这个Parallel.ForEach代码会冻结程序?

更多新手问题: 这段代码从主窗口的列表中抓取了许多代理(我无法弄清楚如何在不同的函数之间使变量可用)并检查每个代理(简单的httpwebrequest),然后将它们添加到名为的列表中finishedProxies。 出于某种原因,当我按下开始按钮时,整个程序挂起。 我的印象是Parallel为每个动作创建单独的线程,只留下UI线程,以便它具有响应性? private void start_Click(object sender, RoutedEventArgs e) { // Populate a list of proxies List proxies = new List(); List finishedProxies = new List(); foreach (string proxy in proxiesList.Items) { proxies.Add(proxy); } Parallel.ForEach(proxies, (i) => { string checkResult; checkResult = checkProxy(i); finishedProxies.Add(checkResult); // update ui /* status.Dispatcher.Invoke( System.Windows.Threading.DispatcherPriority.Normal, new Action( delegate() { […]

如何从另一个线程更新GUI上的文本框

我是C#的新手,我正在尝试创建一个简单的客户端服务器聊天应用程序。 我在我的客户端窗体上有RichTextBox,我正在尝试从另一个类的服务器更新该控件。 当我尝试这样做时,我得到错误: “跨线程操作无效:控制textBox1从其创建的线程以外的线程访问”。 这是我的Windows窗体的代码: private Topic topic; public RichTextBox textbox1; bool check = topic.addUser(textBoxNickname.Text, ref textbox1, ref listitems); 主题类: public class Topic : MarshalByRefObject { //Some code public bool addUser(string user, ref RichTextBox textBox1, ref List listBox1) { //here i am trying to update that control and where i get that exception textBox1.Text += […]