小编Abb*_*bas的帖子

定时器没有在C#中复位

嗨我在C#win表单应用程序中重置Timer控件时遇到问题.

我正在开发一个简单的倒数计时器.

样品

当我点击start它从59秒开始倒计时.我需要计时器从我点击Start按钮开始重启.

代码 timer1_tick

if (hours==0 && minutes==0 && seconds==0)
{
    hours = 0;
    minutes = 1;
    seconds = 0;
}
else
{
    if (seconds < 1)
    {
        seconds = 59;
        if (minutes == 0)
        {
            minutes = 59;
            if (hours != 0)
               hours -= 1;
        }
        else
        {
            minutes -= 1;
        }
    }
    else
        seconds -= 1;

    lblTime.Text = hours + @":" + minutes + @":" + seconds;
}
Run Code Online (Sandbox Code Playgroud)

和代码 btnStart_Click

timer1.Enabled = false; …
Run Code Online (Sandbox Code Playgroud)

c# timer winforms

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

使用已计算的元素

我发现自己在linq语句中重复计算,我想知道我是否可以某种方式访问​​已经计算过的元素.这就是我在做的事情:

var result = testdata.GroupBy(a => new { a.reportinggroup, a.commodity, a.timestep.Year })
                     .Select(g => new EndResult
                            {
                                rundate = rundate.ToShortDateString(),
                                price = g.Sum(a => (a.timestep.ispeak()) ? a.price : 0) / g.Sum(a => (a.timestep.ispeak()) ? 1 : 0),
                                valueposition = g.Sum(a => (a.timestep.ispeak()) ? a.position * a.price : 0) / (g.Sum(a => (a.timestep.ispeak()) ? a.price : 0) / g.Sum(a => (a.timestep.ispeak()) ? 1 : 0)),

                            }).ToList();
Run Code Online (Sandbox Code Playgroud)

哪个工作正常.

这就是我想要做的事情:

var result = testdata.GroupBy(a => new { a.reportinggroup, a.commodity, a.timestep.Year })
                     .Select(g => …
Run Code Online (Sandbox Code Playgroud)

c# linq

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

代码首先仍在尝试创建数据库

即使数据库初始化程序设置为CreateIfNotExists,我也总是遇到此异常.

Additional information: Cannot create file 'C:\\Users\\Krab\\Documents\\Visual Studio 2013\\Projects\\Customer_UI\\customers2.mdf' because it already exists. Change the file path or the file name, and retry the operation.

CREATE DATABASE failed. Some file names listed could not be created. Check related errors.
Run Code Online (Sandbox Code Playgroud)

为什么EF尝试创建数据库,即使它已经存在?

App.config中

 <connectionStrings>
    <add name="Customer.CustomersContext" connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename='C:\\Users\\Krab\\Documents\\Visual Studio 2013\\Projects\\Customer_UI\\customers2.mdf';Integrated Security=True;Connect Timeout=30" providerName="System.Data.SqlClient" />
  </connectionStrings>
Run Code Online (Sandbox Code Playgroud)

的DbContext:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.Entity;

namespace Customer
{
    public class CustomersContext : DbContext
    {
        public CustomersContext() : base("Customer.CustomersContext")
        { …
Run Code Online (Sandbox Code Playgroud)

.net c# entity-framework

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

如何通过HTML和JavaScript发送电子邮件?

我的网站上有联系表格,我想发一个发送按钮.我不希望计算机上的电子邮件程序启动,我只想按下按钮立即将文本发送到我的电子邮件.我现在已经在互联网上搜索了几周而且我放弃了.

<form method="post" name="contact" action="#">
    <label for="author">Name:</label>
    <input type="text" id="author" name="author" class="required input_field" />
    <div class="cleaner h10"></div>

    <label for="email">Email:</label>
    <input type="text" class="validate-email required input_field" name="email" id="email" />
    <div class="cleaner h10"></div>

    <label for="subject">Subject:</label>
    <input type="text" class="validate-subject required input_field" name="subject" id="subject"/>                             
    <div class="cleaner h10"></div>

    <label for="text">Message:</label>
    <textarea id="text" name="text" rows="0" cols="0" class="required"></textarea>
    <div class="cleaner h10"></div>             

    <input type="submit" value="Send" id="submit" name="submit" class="submit_btn float_l" />
    <input type="reset" value="Reset" id="reset" name="reset" class="submit_btn float_r" />
</form>
Run Code Online (Sandbox Code Playgroud)

html javascript email send

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

捏缩放在列表框中的图像

我正在尝试在我的应用程序中实现压缩缩放.我找到了这篇文章(在Silverlight中正确缩放 - 缩放),它可以很好地适用于一个图像.但问题是,我的图像在列表框内,如下面的XAML所示:

<ListBox x:Name="lstImage" Margin="-20,-23,-12,32" Height="709" Width="480">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <Image Source="{Binding Path=ImageSource}" VerticalAlignment="Top" Margin="10,12,10,10" Width="640" Height="800">
            </Image>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>
Run Code Online (Sandbox Code Playgroud)

我无法理解如何实施该解决方案.提前致谢.

silverlight-toolkit windows-phone-7 windows-phone-7.1

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

MessageBox.Show()冻结执行:windows表单c#

美好的一天.我有一个表格和一个背景工作者.在bw_Dowork事件中,有些情况需要使用MessageBox.Show()打印消息(即YES?NO框).但是,每当我调用messageBox.Show()方法时,执行都会冻结,并且表单不允许我单击我的选择(即是/否).有时,如果我想工作,我必须在消息显示时快速点击.否则当我给出一秒钟的间隙时它会冻结.我使用MessageBox.Show()的实例示例如下所示:

private void bw_DoWork(object sender, DoWorkEventArgs e)
{
    if (fileFTP.Exists == false)
    {
        _busy.WaitOne();

        if ((worker.CancellationPending == true))
        {
            e.Cancel = true;
            return;
        }

        SetText("File Ftp.exe are missing. This file are required to preform update, please contact yout system administrator to retrive Ftp.exe", true);
        MessageBox.Show("File Ftp.exe are missing. This file are required to preform update, please contact yout system administrator to retrive Ftp.exe");
        goto ExitProgram;
    }  
}
Run Code Online (Sandbox Code Playgroud)

在我对网上做了一些研究之后,有人建议MessageBox干扰接口线程.这使我使用代理触发消息,但都无济于事.我不得不删除所有的MessageBoxes.离开时仍然会在被解雇时冻结我的执行.请任何帮助将不胜感激.

c# messagebox winforms

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

使用wpf中的<character重命名按钮

我有一个WPF应用程序,我尝试重命名这样的按钮 << Précédent

<Button Content="Suivant >>" Background="#FFF9F7F7" Margin="0,0,100,8"
        HorizontalAlignment="Right" Width="75" Height="22" VerticalAlignment="Bottom"
        RenderTransformOrigin="0.5,0" BorderBrush="CadetBlue"  BorderThickness="2" />
<Button Content="<< Précédent" Background="White" Margin="0,0,180,8"
        HorizontalAlignment="Right" Width="75" Height="22" VerticalAlignment="Bottom"
        BorderBrush="CadetBlue"  BorderThickness="2" />
Run Code Online (Sandbox Code Playgroud)

但第二个按钮名称中出现错误

  1. 为什么这不起作用?
  2. 我该如何解决?

.net c# wpf

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

ORDER BY的SQL查询语法不起作用

我是C#的新手,但我非常了解SQL.我有一个在SQL编辑器中工作正常的查询,但我无法将其集成到我的代码中.它抛出错误的SQL语法异常.原始SQL查询工作正常是:

从Table_A中选择不同的描述,其中id ='001'按顺序排序;

C#字符串就像:

_cmd.CommandText = "select distinct description from Table_A where Plant_ID =" + _selectedPlantID + "order by description";
Run Code Online (Sandbox Code Playgroud)

删除+ "order by description部件时,上述查询在C#程序中有效.这_selectedPlantID是唯一可以在程序中获得价值的变量.我很确定应该有一些引号问题,但对我来说一切看起来都很好,所以想知道是否还有其他特定方式在C#中编写这个?

c# sql

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

通过代码更改PrintDialog中的打印机名称

我试图通过代码更改 PrintDialog 的选定打印机。我正在创建一个需要打印的图像,但图像的大小决定了应使用哪台打印机。我有我想要使用的打印机的名称,但我只是不知道在哪里更改该值。任何帮助都可以是 VB.NET 或 C# 形式。

谢谢。

.net printing printdialog

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

复选框中的C#

如何动态检查框而不触发检查更改功能?我有20个动态创建的复选框,我有一个下拉列表,用于确定要检查的复选框数.

如果我选中3并单击第6个复选框,则应选中复选框9,7和8.在此过程中,我不想触发checkchanged功能.

CheckBox cb1 = (CheckBox)sender;
selectedbox = int.Parse(cb1.Name);

for (int i = 1; i < selectedquantity; i++)
{
    premiumticket[selectedbox].Checked = true; 
    //here check changed firing  i dont want that
    selectedbox++;
}
Run Code Online (Sandbox Code Playgroud)

c# winforms

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