小编beh*_*nam的帖子

绘制后如何将圆圈视为控件? - 移动和选择形状

实际上,点击每个圆圈之后我想要改变它的颜色,例如,我希望它变成红色,总的来说,我想把它当作对照.

我知道如何在双击图片框时绘制代表图表节点的圆圈.我正在使用以下代码:

        public Form1()
    {
        InitializeComponent();

        pictureBox1.Paint += new PaintEventHandler(pic_Paint);
    }

    public Point positionCursor { get; set; }
    private List<Point> points = new List<Point>();
    public int circleNumber { get; set; }

    private void pictureBox1_DoubleClick(object sender, EventArgs e)
    {
        positionCursor = this.PointToClient(new Point(Cursor.Position.X - 25, Cursor.Position.Y - 25));

        points.Add(positionCursor);
        Label lbl = new Label();
        lbl.BackColor = Color.Transparent;
        lbl.Font = new Font("Arial", 7);

        lbl.Size = new Size(20, 15);

        if (circleNumber >= 10)
        {
            lbl.Location = new Point(points[circleNumber].X + 3, points[circleNumber].Y + 6); …
Run Code Online (Sandbox Code Playgroud)

.net c# gdi+ picturebox winforms

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

5
推荐指数
2
解决办法
9041
查看次数

PrivateObject 中未找到类型的构造函数错误

我正在为计算软件编写一个单元测试。在测试用例中,我使用了“ PrivateObject”来访问私有方法“ sendNumberToCalculation()”,但我得到了类型未找到的错误构造函数。

    public class CalculationTest
{
    [TestMethod]
    public void sendNumberToCalculationTest()
    {

        // -- Act
        PrivateObject obj = new PrivateObject(typeof(Calculation));
        Tokenization token = new Tokenization("5*10-18/(3+19)");
        PolishNotation polish = new PolishNotation(token.MathExpressionParser());

        double expected = 49.19;

        // -- Actual
        double actual = Convert.ToDouble(obj.Invoke("sendNumberToCalculation", polish));

        // -- Assert
        Assert.AreEqual(expected, actual);
    }
}

    public class Calculation
{

    private Tokenization token;

    private PolishNotation polish;
    private Stack<double> numbers = new Stack<double>();
    private Stack<string> operators = new Stack<string>();

    public Calculation(string expression)
    {
        token = new …
Run Code Online (Sandbox Code Playgroud)

c# unit-testing

5
推荐指数
1
解决办法
1902
查看次数

如何防止使用事件重复代码

我是初学程序员,我觉得我不必要地重复代码.我想制作一个由16个图片框组成的图片益智游戏.问题是我觉得我必须为每个图片框的事件重复代码,如下例所示:

       Point move;
    bool isDragging = false;
    private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
    {
        isDragging = true;
        move = e.Location;
    }

    private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
    {

        if(isDragging == true)
        {
            pictureBox1.Left += e.X - move.X;
            pictureBox1.Top += e.Y - move.Y;
            pictureBox1.BringToFront();
        }

    }

    private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
    {
        isDragging = false;
    }
Run Code Online (Sandbox Code Playgroud)

c#

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

如何从存储过程中获取输出结果在C#中使用Entity Framework?

我正在开发一个ASP.NET MVC项目; 我的目标是从表中准备一份报告,这是我第一次写Linq代码但是速度太慢了.

之后我编写了一个SQL查询,它的速度非常快,我想使用存储过程从我的表中获取报表数据.事实上,我的项目非常简单:它有两个日期 - 开始日期和结束日期 - 并在表格中显示结果.

我想编写我的存储过程以从C#代码获取两个参数 - 开始日期和结束日期,然后在C#中的变量中返回输出.

第一个问题:如何将我的SQL查询转换为具有两个参数的存储过程,开始日期和结束日期?

第二个问题:如何在C#中返回输出结果?

SELECT 
    CAST(date_rec_slash AS DATETIME), COUNT(code_marz) AS total,
    CASE
       WHEN code_marz = 1 THEN 'a'
       WHEN code_marz = 2 THEN 'b'
       WHEN code_marz = 3 THEN 'c'
       WHEN code_marz = 4 THEN 'd'
       WHEN code_marz = 5 THEN 'e'
    END
FROM 
    dbo.tbl_bar 
WHERE 
    CAST(date_rec_slash AS DATETIME) BETWEEN '2017/12/01' AND '2017/12/31'
GROUP BY 
    CAST(date_rec_slash AS DATETIME), code_marz
ORDER BY 
    CAST(date_rec_slash AS DATETIME) ASC;
Run Code Online (Sandbox Code Playgroud)

C#:

var spResults = db.Database.SqlQuery<tbl_bar>("Report");
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

c# sql-server stored-procedures

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

参数化查询需要参数'@Id',这是未提供的

我正在编写一个使用方法(parameters.add)的软件,但是当我向数据库添加数据时,我得到以下错误:

参数化查询需要参数'@Id',这是未提供的.

我看到了几个主题,但我无法解决我的问题.

参数化查询需要未提供的参数######

参数化查询需要参数,该参数未提供

我把c#代码和存储过程代码放在下面:

private void btnSave_Click(object sender, EventArgs e)
        {
            string cs = "Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=TranscactionAccountNumber;Data Source=DESKTOP-5DJFFQP";
            string name = txtName.Text;
            int shomarepeygiri = int.Parse(txtShomarePeygiri.Text);
            string date = dtpDate.Shamsi;
            decimal mablagh = decimal.Parse(txtMablagh.Text);
            string comment = txtComment.Text;
            using (cn = new SqlConnection(cs))
            using (cmd = new SqlCommand("InsertTransaction", cn))
            {
                cmd.Parameters.Add("@Id",SqlDbType.Int);
                cmd.Parameters.Add("@Name", SqlDbType.NVarChar, 100).Value = name;
                cmd.Parameters.Add("@ShomarePeygiri", SqlDbType.Int).Value = shomarepeygiri;
                cmd.Parameters.Add("@Mablagh", SqlDbType.Decimal).Value = mablagh;
                cmd.Parameters.Add("@Comment", SqlDbType.NVarChar).Value = comment;
                cmd.Parameters.Add("@Date", SqlDbType.VarChar).Value = date;
                if (cn.State == ConnectionState.Closed) …
Run Code Online (Sandbox Code Playgroud)

c# sql-server ado.net stored-procedures

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