小编Con*_*uit的帖子

C# - 表单构造函数中的代码未执行

C#相对较新; 希望我只是忽略了一些简单的事情.

我有一个名为'Exercise1'的表单,其中包含一个名为'drawingArea'的图片框和几个按钮.Exercise1的构造函数的代码如下:

public Exercise1()
{
    InitializeComponent();
    paper = drawingArea.CreateGraphics();
    balloon = new Balloon("redBalloon", Color.Red, drawingArea.Width / 2, 
        drawingArea.Height / 2, 30);
    paper.Clear(Color.White);
    balloon.Display(paper);   
}
...
Run Code Online (Sandbox Code Playgroud)

'paper'和'balloon'在构造函数上方创建为全局变量,用于表单上的其他方法.'paper'和'balloon'都在构造函数中在表单上定义的其他方法中初始化.

无论出于何种原因,命令

paper.Clear(Color.White);
Run Code Online (Sandbox Code Playgroud)

balloon.Display(paper);
Run Code Online (Sandbox Code Playgroud)

哪个应该清除图片框并显示一个红色椭圆,不执行(至少可见).是什么赋予了?

更新: 想想我会喜欢这个网站...你们很快!
@Nitesh:练习1的构造函数是从另一个表单调用的.代码如下:

private void button1_Click(object sender, EventArgs e)
        {
            int exSelector = (int)numericUpDown1.Value;
            switch (exSelector)
            {
                case 1:
                    Exercise1 form1 = new Exercise1();
                    form1.Show();
                    break;
...
Run Code Online (Sandbox Code Playgroud)

@Sean Dunford:是的,是的.
@RBarryYoung:玩了一下,但没有运气.什么命令触发Exercise1的Form_Load事件?

更新:此更改的代码按预期工作:

public Exercise1()
        {
            InitializeComponent();
            paper = drawingArea.CreateGraphics();
            drawingArea.BackColor = Color.White;
            drawingArea.Paint += new PaintEventHandler(this.drawingArea_Paint);
            balloon = …
Run Code Online (Sandbox Code Playgroud)

c# winforms

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

unordered_set :: find的复杂性是否可预测?

在寻找适合我正在构建的应用程序的容器时,我遇到了文档unordered_set.鉴于我的应用程序通常只需要insertfind函数,这个类似乎很有吸引力.然而,我find被O(1)摊销的事实略微推迟,但O(n)最坏的情况 - 我会经常使用该函数,它可能会成就或破坏我的应用程序.导致复杂性飙升的原因是什么?进入O(n)搜索的可能性是否可预测?

c++ complexity-theory data-structures c++11

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

Apache Kafka:由于java.io.IOIO导致会话<xx>关闭的异常:长度不合理

阿帕奇卡夫卡0.9.0

尝试通过使用者执行提取操作时,我在zookeeper日志中遇到了上述异常。这是我在使用者上创建提取请求的方式:

kafka.api.FetchRequest req = new FetchRequestBuilder().clientId(clientId)
                                                      .addFetch(topic, 0, 0L, 100)
                                                      .build();
FetchResponse fetchResponse = simpleConsumer.fetch(req);
Run Code Online (Sandbox Code Playgroud)

java.io.EOFException消费者执行提取操作时,我看到一个。

有什么想法吗??

apache-kafka

5
推荐指数
0
解决办法
832
查看次数

气馁的pragma使用GCC

几乎所有的C++程序都需要标头保护,但是在严格执行命名约定时会很痛苦 - 尤其是在重构期间.当使用GCC(和许多其他编译器)时,我们在预处理器命令中有一个替代方案#pragma once.我看到的反对使用这个命令的建议(例如在v3.4之前缺乏支持)对我的个人项目来说并不十分有说服力.我想#pragma once尽可能使用.

总而言之,海湾合作委员会网站上的这句话让我停下来:

请注意,一般我们不建议使用编译指示; 有关详细说明,请参见函数属性.

也许只是我的低级熟练程度级别的C++体验对我不利,但我没有在该链接所指向的网站上看到该建议的任何解释.是否有人能够用(半)外行人的条款解释他们推荐的理由?

c++ gcc pragma

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

可变参数模板的部分模板特化,其中[Args ...]为空

我有一个类Delegate,声明如下:

template<typename T> class Delegate;

template<typename R, typename... Args>
class Delegate<R(Args...)>
{ /*...*/ };
Run Code Online (Sandbox Code Playgroud)

它可以被实例化为一个返回a ReturnType并且不带参数的函数Delegate<ReturnType()>.我遇到了一个问题,要求我专门()针对这种情况使用类' 运算符,但是在没有编译器错误的情况下无法弄清楚如何强制编译器这样做.

我有以下功能:

template <typename R, typename... Args>
R Delegate<R(Args...)>::operator()(Args... args)
{ /*...*/ }
Run Code Online (Sandbox Code Playgroud)

添加以下特化,我得到一个错误说invalid use of incomplete type 'class Delegate<R()>':

template <typename R>
R Delegate<R()>::operator()()
{ /*...*/ }
Run Code Online (Sandbox Code Playgroud)

但我不能简单地取代Args...void两种,据我已经能够告诉...什么是正确的步骤在这里,和(如果这个问题适用,你感觉额外帮助的),为什么?

c++ partial-specialization variadic-templates c++11

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

"事件处理程序中的可重入调用SetCurrentCellAddressCore" - 仅在单元格行和列索引相等的情况下

我正在创建一个WinForms应用程序,其中包含一个使用a DataGridView来处理简单数据操作的表单.为了确保准确输入,同时减轻混乱(阅读:不使用DataGridViewComboBoxColumn)我有一些事件处理程序暂时将a DataGridViewTextBoxCell转换为等效DataGridViewComboBoxCell连接到已知为"干净"的值,当编辑事件被引发时(通常在单击可编辑单元格时):

private void OnCellEndEdit(object sender, DataGridViewCellEventArgs e)
{
    //construct a textbox cell and set to current value
    DataGridViewTextBoxCell cell = new DataGridViewTextBoxCell();
    cell.Value = dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value;

    //color row if invalid or modified
    UpdateRowStyle(dataGridView.Rows[e.RowIndex]);

    //switch to the new cell and redraw
    dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex] = cell;
    dataGridView.Refresh();
}
Run Code Online (Sandbox Code Playgroud)

private void OnCellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
{
    //construct a combobox cell, link to data, and set to current value
    DataGridViewComboBoxCell cell = new DataGridViewComboBoxCell();
    cell.DataSource = mDropDownValues[dataGridView.Columns[e.ColumnIndex].Name]; …
Run Code Online (Sandbox Code Playgroud)

c# datagridview exception event-handling winforms

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

限制嵌套结构中的构造函数范围

说我有一个令人难以置信的设计类定义如下:

class Outer {
public:
    struct Inner {
        Inner(int innerValue) : foo(innerValue) {};
        int foo;
    };

    Outer(int innerValue) : _inner(innerValue) {};

    const Inner& getInner() const {
        return _inner;
    };

private:
    Inner _inner;
};
Run Code Online (Sandbox Code Playgroud)

我想Outer是能够构造的一个实例的唯一的类Inner,但是在这样一种方式,其他类/功能可以访问_inner.foo时传递给一个参考_inner通过Outer::getInner().这可能吗?有没有更好的方法来实现同等功能?

c++ c++11

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

C ++模板中的函数签名

std::function类模板以这样的方式,当我们希望它包裹类似下面的功能:

void printInt(int integer)
{
    std::cout << int << '\n';
}
Run Code Online (Sandbox Code Playgroud)

我们使用std::function<void(int)>。直到最近,我还以为这是该类的一个细微差别,但是在C ++中搜索委托实现时发现的一个类使用了类似的语法。

到底 void(int)什么,我们用技术术语称之为什么?这似乎是在codepeak 中说“ 带一个int并返回void的函数 ”的标准方法,但是我的直觉告诉我,这简直太过简单了。

其次,我注意到当我看到使用此语法的模板时,它们使用可变参数模板来匹配多个功能签名。从上面的链接:

template <typename T> class delegate;

template<class R, class ...A>
class delegate<R (A...)>
{
...
Run Code Online (Sandbox Code Playgroud)

为什么要声明这样的功能而不是简单地使用以下内容?

template<class R, class ...A>
class delegate
{
...
Run Code Online (Sandbox Code Playgroud)

c++ templates c++11

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

仅限枚举的模板类

有没有办法确保如果特定的模板参数提供强类型枚举(即枚举类)以外的其他东西,模板化的类将无法编译?

c++ enums templates c++11

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

虚函数效率和“final”关键字

考虑一个程序,它有一个类,其中包含如下声明的Foo函数:Foo::fn

virtual void fn();
Run Code Online (Sandbox Code Playgroud)

和一个Foo名为 的子类Bar。将Bar::fn这样声明:

virtual void fn() override final;
Run Code Online (Sandbox Code Playgroud)

导致对fninBar或 的子类的调用Bar更加有效,还是只会阻止 的子类Bar被覆盖fn?如果使用 使调用更加高效final,那么最简单、最有效的定义方法是什么,Bar::fn使其功能与 完全相同Foo::fn

c++ performance vtable c++11

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