小编joh*_*ohn的帖子

C#XML文档网站链接

是否可以在XML文档中包含指向网站的链接?例如,我的方法总结为

///<Summary>
/// This is a math function I found HERE.
///</Summary>
public void SomeMathThing(Double[] doubleArray)
{
   ...
}
Run Code Online (Sandbox Code Playgroud)

当我打字的时候

SomeMathThing(
Run Code Online (Sandbox Code Playgroud)

我希望IntelliSense显示摘要,并选择单击"此处"链接到外部网站.这可能吗?怎么做?

c# xml hyperlink

124
推荐指数
5
解决办法
3万
查看次数

DataGridView ComboBox列:从下拉列表中选择后更改单元格值?

我为我的DataGridView设置了一个ComboBoxColumn,并从枚举中设置了它的可选值.它主要按照我想要的方式运行,但有以下异常.

每当我单击下拉箭头然后选择其中一个枚举值时,它仍然处于"中间"状态,其中未触发CellValueChanged事件.我需要专注于另一个单元格或另一个控件来触发事件.

我还有一个DataGridView的Leaving事件的事件处理程序,它通过确保没有单元格为空来"验证"内容.

因此,如果我创建一行并填充所有单元格并进入(当前为空白)ComboBox列,请将其更改为值,然后单击"运行"按钮; 弹出我的错误对话框,因为ComboBox选择未"保存".

我怎么能绕过这个?有没有办法在我从下拉列表中选择一个值后自动"设置"该值?

谢谢!

c# datagridview

18
推荐指数
3
解决办法
4万
查看次数

标记枚举的C#int

可能重复:
C#int到枚举转换

是否有可能将int转换为标志组合枚举?因此,如果

[Flags]
public enum Foo {a = 0x80,
                 b = 0x40,
                 c = ...,
                 ...
                 h = 0x1,
                 i = 0};
Run Code Online (Sandbox Code Playgroud)

是否可以(或某种可能)做

Foo fooInstance = (Foo)6;
Run Code Online (Sandbox Code Playgroud)

fooInstance将是00000110?

谢谢!

c# enums bitflags

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

c#公共嵌套类或更好的选项?

我有一个控制电路,它有多种设置,可以连接任意数量的传感器(每个都有自己的设置).这些传感器只能与控制电路一起使用.我想过使用嵌套类,如下所示:

public class ControlCircuitLib
{
    // Fields.
    private Settings controllerSettings;
    private List<Sensor> attachedSensors;

    // Properties.
    public Settings ControllerSettings
    { get { return this.controllerSettings; } }

    public List<Sensor> AttachedSensors
    { get { return this.attachedSensors; } }

    // Constructors, methods, etc.
    ...

    // Nested classes.
    public class Settings
    {
       // Fields.
       private ControlCircuitLib controllerCircuit;
       private SerialPort controllerSerialPort;
       private int activeOutputs;
       ... (many, many more settings)

       // Properties.
       public int ActiveOutputs
       { get { return this.activeOutputs; } }
       ... (the other Get properties …
Run Code Online (Sandbox Code Playgroud)

c# nested-class

14
推荐指数
2
解决办法
5683
查看次数

线程:如何在完成后重新启动线程?

我有一个void DoWork(object input)大约需要5秒才能完成的方法.我读过这个ThreadThreadPool这些更长的操作更合适,但我遇到了一个问题.

我点击一个按钮,调用threadRun.Start(input)哪个运行并完成正常.我再次单击该按钮并收到以下异常:

Thread is running or terminated; it cannot restart.

你能否"重用"一个线程?我应该使用ThreadPool吗?与ThreadPool相比,为什么Thread"更适合更长时间的操作"?如果你不能重复使用一个线程,为什么要使用它(即它提供了哪些优势)?

c# multithreading

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

C#错误代码与异常

我有一个控制电路,我通过串口进行通信.如果响应命令与某种格式不匹配,我认为它是一个错误,并想知道我是否应该返回错误代码或抛出异常?例如:

public double GetSensorValue(int sensorNumber)
{
   ...
   string circuitCommand = "GSV,01," + sensorNumber.ToString();   // Get measurement command for specified sensor.
   string responseCommand;
   string expectedResponseCommand = "GSV,01,1,OK";
   string errorResponseCommand = "ER,GSV,01,1,62";

   responseCommand = SendReceive(circuitCommand); // Send command to circuit and get response.

   if(responseCommand != expectedResponseCommand) // Some type of error...
   {
      if(responseCommand == errorResponseCommand) // The circuit reported an error...
      {
         ...  // How should I handle this? Return an error code (e.g. -99999) or thrown an exception?
      }
      else   // …
Run Code Online (Sandbox Code Playgroud)

c# error-handling

6
推荐指数
1
解决办法
6329
查看次数

C#DataGridViewCheckBoxColumn Hide/Gray-Out

我有DataGridView几列和几行数据.其中一列是a DataGridViewCheckBoxColumn和(根据行中的其他数据)我希望选择"隐藏"某些行中的复选框.我知道如何让它只读,但我更希望它不显示或至少显示不同(灰显)比其他复选框.这可能吗?

c# datagridview datagridviewcheckboxcell

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

C#静态表单已添加到项目中?

我想为程序创建一个自定义消息框,所以我添加了一个Windows表单项.我希望它表现得像MessageBox是静态的,我只是打电话MessageBox.Show(a, b, c, ...).然而,在表单设计器中,我看不出如何使其静态化.我可以添加static到代码中吗?我在设计师模式中缺少属性设置吗?

谢谢!

c# forms static

4
推荐指数
1
解决办法
7534
查看次数

PropertyGrid:ExpandableObjectConverter出现问题

我创建了一个类来显示一个PropertyGrid包含另一个类的类; 我希望这个类可以扩展,所以我尝试添加[TypeConverter(typeof(ExpandableObjectConverter))]但它似乎不起作用.这是我尝试的一个简单示例:

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();

        this.propertyGrid1.SelectedObject = new Class1();
    }
}

public class Class1
{
    string name;

    public string Name
    {
        get { return this.name; }
        set { this.name = value; }
    }

    Class2 class2;

    public Class2 Class2
    {
        get { return this.class2; }
        set { this.class2 = value; }
    }
}

[TypeConverter(typeof(ExpandableObjectConverter))]
public class Class2
{
    string stuff = "none";

    public string Stuff
    {
        get { return …
Run Code Online (Sandbox Code Playgroud)

c# propertygrid

4
推荐指数
1
解决办法
3263
查看次数

C#Enum索引问题

是否可以使用索引整数来获取enum值?例如,如果......

public enum Days { Mon, Tues, Wed, ..., Sun};
Run Code Online (Sandbox Code Playgroud)

...在某种程度上可以写出类似......

Days currentDay = Days[index];
Run Code Online (Sandbox Code Playgroud)

谢谢!

c# indexing enums

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