小编def*_*ale的帖子

强制应用程序关闭系统关闭

我有一个Windows窗体应用程序,当主窗口关闭时,它会显示一个基本对话框,确认操作.如果用户决定取消应用程序,则取消退出.

但是,当应用程序最小化并且用户想要关闭PC时,关闭序列将停止,因为我的应用程序正在等待用户确认应用程序关闭(显示对话框).

我想添加一个用于超时的计时器,如果在一定时间内没有答案,请自动关闭应用程序,但即使这是一种方法,它肯定不是每个其他应用程序如何做到的.

那么,除非系统正在关闭,否则在其他情况下确定应用程序关闭的最佳解决方案是什么?

谢谢!

c# shutdown winforms

27
推荐指数
3
解决办法
8013
查看次数

类型不匹配:无法从StringBuilder转换为String

此方法返回给定URL的源.

private static String getUrlSource(String url) {
    try {
        URL localUrl = null;
        localUrl = new URL(url);
        URLConnection conn = localUrl.openConnection();
        BufferedReader reader = new BufferedReader(
            new InputStreamReader(conn.getInputStream()));
        String line = "";
        String html;
        StringBuilder ma = new StringBuilder();
        while ((line = reader.readLine()) != null) {
            ma.append(line);
        }
        return ma;
    } catch (Exception e) {
        Log.e("ERR",e.getMessage());
    }
}
Run Code Online (Sandbox Code Playgroud)

它给了我这个错误:

Type mismatch: cannot convert from StringBuilder to String
Run Code Online (Sandbox Code Playgroud)

还有两个选择:

  1. Change the return type to StringBuilder. 但我希望它返回一个字符串.
  2. Change type of ma to …

java android

26
推荐指数
1
解决办法
7万
查看次数

System.ComponentModel.Win32Exception:操作成功完成

我有时会在运行Windows窗体应用程序时遇到此异常:

System.ComponentModel.Win32Exception: The operation completed successfully
   at System.Drawing.BufferedGraphicsContext.CreateCompatibleDIB(IntPtr hdc, IntPtr hpal, Int32 ulWidth, Int32 ulHeight, IntPtr& ppvBits)
   at System.Drawing.BufferedGraphicsContext.CreateBuffer(IntPtr src, Int32 offsetX, Int32 offsetY, Int32 width, Int32 height)
   at System.Drawing.BufferedGraphicsContext.AllocBuffer(Graphics targetGraphics, IntPtr targetDC, Rectangle targetRectangle)
   at System.Drawing.BufferedGraphicsContext.AllocBufferInTempManager(Graphics targetGraphics, IntPtr targetDC, Rectangle targetRectangle)
   at System.Drawing.BufferedGraphicsContext.Allocate(IntPtr targetDC, Rectangle targetRectangle)
   at System.Windows.Forms.Control.WmPaint(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.DataGridView.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
Run Code Online (Sandbox Code Playgroud)

可能是什么原因造成的?

.net c# win32exception winforms

25
推荐指数
2
解决办法
3万
查看次数

EventHandlers和C#类析构函数/ Dispose

我对C#Classes和它们的解构函数有点困惑.

我必须在构造函数中获取的类实例中使用一些事件处理程序:

 public Foo(IFooHandler handler)
 {
     handler.Load += Load;
     handler.Close += Close;
 }
Run Code Online (Sandbox Code Playgroud)

当Foo类被销毁时,我需要取消订阅该事件.我IDisposable在那里或在解构器中实现和取消订阅吗?我需要消耗那些事件,我不能以另一种方式去做.

对于其中一个类,我创建一个实例,检查进度,然后类实例超出范围.对于另一个,它一直停留在MainForm表格关闭之前.第一个是我担心的,因为它可能仍然有对该事件处理程序的引用而没有正确地去.

我不想泄漏记忆.何时以及如何取消订阅?

c# events delegates winforms

24
推荐指数
2
解决办法
1万
查看次数

需要将lowercase_underscore字符串更改为camelCase

我需要更改字符串:underbar + lowercase = uppercase.(和相反的)

my_name -> myName
Run Code Online (Sandbox Code Playgroud)

有没有图书馆或其他东西来帮助解决这个问题?

java case-sensitive

22
推荐指数
3
解决办法
1万
查看次数

调整c#窗体大小时防止窗口重绘

我可以收听什么窗口消息或事件,以阻止窗口重绘其每个像素的大小?

也就是说,当用户点击窗口的边缘并开始重新调整大小时,我不想重新绘制整个内容,直到他放开为止.这是因为出于某种原因,它目前在调整大小时可能会因为一切都重新对接而不是重新对齐.

我尝试了WM_SIZING,但这只是告诉我它正在重新调整大小,我想知道大小的开始和结束,所以我可以暂停布局,直到用户停止调整大小.

c# resize winforms form-control

20
推荐指数
1
解决办法
1万
查看次数

如何在Winforms按钮上模拟"mailto:"调用点击?

我将发送一个带有给定地址的电子邮件,打开标准电子邮件程序,如"mailto:",在a-tag中即可完成,但只需点击一下按钮.

怎么样?

email button winforms

19
推荐指数
2
解决办法
2万
查看次数

Visual Studio的隐藏功能赢得了设计师的青睐

视觉工作室最受喜爱和讨厌的人之一必须是表单设计师.

创建简单的表单/用户控件布局通常是轻而易举的.设置属性和添加事件很容易.

设置工具箱以使用您自己的控件可能会有点困难,让ToolBoxIcons显示可能会很痛苦.通过可视继承使用第三方组件可以抛出设计者.在设计上使用多重继承可能非常困难.

那么你最喜欢的"隐藏"和/或明显的视觉工作室设计师功能是什么.

windows-forms-designer visual-studio winforms

19
推荐指数
4
解决办法
8343
查看次数

java hibernate未知列''in'字段列表'

我需要帮助.

当我使用getAllStreets()方法时我在HQL中有错误:

org.hibernate.exception.SQLGrammarException: Unknown column 'this_1_.houses_id' in 'field list'
Run Code Online (Sandbox Code Playgroud)

我猜他一定要写this_1_id代替this_1_.houses_id

可能是我做错了实体和关系?

2实体 - 房屋和街道

ER - 型号:

表街道

  • ID
  • 名称
  • Houses_id

表房子

  • ID
  • 名称

我的课程:

@Entity
@Table(name="Streets")
public class Street {
    private Long id;
    private String name;
    private Long houses_id;
    private House house;
    public Street(){}    
    @Id
    @GeneratedValue(generator="increment")
    @GenericGenerator(name="increment", strategy="increment")
    @Column(name="id")
    public Long getId() {
        return id;
    }
    public void setId(Long id) {
        this.id = id;
    }
    @Column(name="name")
    public String getName() {
        return name;
    } …
Run Code Online (Sandbox Code Playgroud)

java hibernate

16
推荐指数
2
解决办法
6万
查看次数

Windows窗体的透明度表示文本框

我在C#中使用Windows窗体,我需要使文本框的背景颜色透明.我有一个从0到255的轨道栏,它应该控制它,但我遇到了一些麻烦.我今天早些时候提出了一个问题问同样的问题,但没有成功.

这是我目前的代码:

private void trackAlpha_ValueChanged(object sender, EventArgs e)
{
    newColor = Color.FromArgb(trackAlpha.Value, colorDialog.Color.R, colorDialog.Color.G, colorDialog.Color.B);
    colorDialog.Color = newColor; // The Windows dialog used to pick the colors
    colorPreview.BackColor = newColor; // Textbox that I'm setting the background color
}
Run Code Online (Sandbox Code Playgroud)

问题是绝对没有任何反应.关于为什么这不起作用的任何想法?

在上一个问题上,这个好人说了些什么SetStyle(ControlStyles.SupportsTransparentBackColor, true);,但我不知道我应该把它放在哪里.

c# transparency textbox alpha winforms

15
推荐指数
3
解决办法
6万
查看次数