小编Ral*_*alt的帖子

触发按钮单击代码

所以当点击"添加播放器"按钮时,我有以下代码

private void addPlayerBtn_Click_1(object sender, EventArgs e)
{
    //Do some code
}
Run Code Online (Sandbox Code Playgroud)

我想从我的SDK中触发此代码.这是我尝试过的

private void command()
{       
    addPlayerBtn_Click_1(object sender, EventArgs e);          
}
Run Code Online (Sandbox Code Playgroud)

一旦我放入线路,我就会收到很多错误

 addPlayerBtn_Click_1(object sender, EventArgs e) 
Run Code Online (Sandbox Code Playgroud)

有人可以告诉我如何编写代码,以便我可以通过在代码中写入来触发事件吗?

c# events

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

具体使用Try/Catch

作为编程新手我刚刚发现你可以专门捕获某些类型的错误并将代码绑定到那种类型的错误.

我一直在研究这个主题,我不太明白语法,例如

catch (InvalidCastException e) 
 {
 }
Run Code Online (Sandbox Code Playgroud)

我理解InvalidCastException正在处理的错误类型,但我不确定是什么e.

有人可以解释一下吗?

c# exception-handling try-catch

10
推荐指数
4
解决办法
489
查看次数

方向更改后如何更改网格布局

我正在创建一个win8应用程序,我需要更改网格的布局,以便当用户在方向之间切换时一切都适合在屏幕上。我知道我需要使用,VisualStateManager但我听不懂任何教程。如果我有此代码:

<Grid>
  <Button x:Name="button1"  Margin="188,73,286,0" VerticalAlignment="Top"/>
  <Button x:Name="button2"  Margin="236,73,238,0" VerticalAlignment="Top"/>
  <Button x:Name="button3"  Margin="284,73,190,0" VerticalAlignment="Top"/>
</Grid>
Run Code Online (Sandbox Code Playgroud)

当方向从横向更改为纵向时,我将如何使用可视状态管理器来更改按钮,使其现在以一列(一个在另一个之上)而不是在行中定向?

谢谢

c# wpf xaml windows-8

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

如何打开最大化的Internet Explorer?

我必须使用C#打开最大化的Internet Explorer.我尝试过以下方法:

try
{
    var IE = new SHDocVw.InternetExplorer();
    object URL = "http://localhost/client.html";

    IE.ToolBar = 0;
    IE.StatusBar = true;
    IE.MenuBar = true;
    IE.AddressBar = true;
    IE.Width = System.Windows.Forms.SystemInformation.VirtualScreen.Width;
    IE.Height = System.Windows.Forms.SystemInformation.VirtualScreen.Height;

    IE.Visible = true;

    IE.Navigate2(ref URL);
    ieOpened = true;

    break;
}
catch (Exception)
{

}
Run Code Online (Sandbox Code Playgroud)

我可以打开不同的大小,但我找不到如何打开最大化的IE.我检查了msdn,没有属性可以最大化.

请给我一些建议.

PS:我正在开发C#控制台应用程序,.Net4.5和VS2012

c# internet-explorer shdocvw

4
推荐指数
2
解决办法
4695
查看次数

将double转换为科学计数法,并在小数点后使用特定数字

我想将double转换为科学记数法,如下所示:

-0.00752382528 => -.752383E-1
Run Code Online (Sandbox Code Playgroud)

我可以用.ToString()或Regex做到这一点吗?

c# double scientific-notation

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

数据源中String类型的给定值无法转换为指定目标列的int类型

我试图从xml文件中读取值,然后使用bulkcopy将数据插入到我的数据库中.

我正在使用一个自定义类:

class Customer
    {
        public int CustomerID { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public int ShowsNumber { get; set; }
        public int VisitNumber { get; set; }
        public int Cancellation { get; set; }
    }
Run Code Online (Sandbox Code Playgroud)

我读了这样的数据:

List<Customer> customersList =
                (
                    from e in XDocument.Load(file).Root.Elements("cust")
                    select new Customer
                    {
                        CustomerID = (int)e.Attribute("custid"),
                        FirstName = (string)e.Attribute("fname"),
                        LastName = (string)e.Attribute("lname"),
                        ShowsNumber = (int)e.Attribute("count_noshow"),
                        VisitNumber = (int)e.Attribute("count_resos"),
                        Cancellation = (int)e.Attribute("count_cancel"),
                    }).ToList(); …
Run Code Online (Sandbox Code Playgroud)

c# linq linq-to-xml sqlbulkcopy

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

宪章未定义错误

我正在尝试使用Chartist.js框架为我的网站创建图表。但是由于某些原因,我不断收到错误“未定义Chartist”

我不知道如何解决此错误。请参见下面的代码:

<!DOCTYPE html>
<html>
<head>
    <script src="https://cdn.jsdelivr.net/chartist.js/latest/chartist.min.js"></script>
    <link href="https//cdn.jsdelivr.net/chartist.js/latest/chartist.min.css" rel="stylesheet" type="text/css" />
    <link href='http://fonts.googleapis.com/css?family=Oxygen:300' rel='stylesheet' type='text/css'>
    <meta charset="utf-8">
    <title>Chartist.js - Simple line chart</title>
    <script>
       // THIS IS WHERE THE ERROR OCCURS
       new Chartist.Line('.ct-chart', {
       labels: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri'],
       series: [
                 [2, 3, 2, 4, 5],
                 [0, 2.5, 3, 2, 3],
                 [1, 2, 2.5, 3.5, 4]
               ]
        }, {
          width: 500,
          height: 300
       });

     </script>
     </head>

     <body>
     <div class="ct-chart"></div>

     </body>
     </html>
Run Code Online (Sandbox Code Playgroud)

有人知道我在做什么错吗?提前致谢。

javascript angularjs chartist.js angular-chartist.js

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

布尔没有更新

我有一个bool叫attackQ按下按钮时设置为true (Q是攻击)

我用断点试图自己解决问题.设置attack为true 的代码行正在运行,但实际上并没有设置attack为true ...我是XNA的新手,很抱歉,如果这是一个明显的解决方案.这是代码.. :( ps我遗漏了很多与问题无关的代码)

public class Player
{

    Animation playerAnimation = new Animation();

public void Update(GameTime gameTime)
    {
        keyState = Keyboard.GetState()

        if (keyState.IsKeyDown(Keys.Q))
        {
            tempCurrentFrame.Y = 0;
           *** playerAnimation.Attack = true; *** This line of code runs yet doesn't actually work
        }

public class Animation
{


    bool  attack;

public bool Attack
    {
        get { return attack; }
        set { value = attack; }
    }

public void Update(GameTime …
Run Code Online (Sandbox Code Playgroud)

c# xna

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

如何在Generic.Xaml中获取自定义控件的事件处理程序

我试图用两个按钮创建一个自定义控件(例如)。我有一个Generic.Xaml文件,看起来像这样

<Style TargetType="local:DoubleButton">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="local:DoubleButton">
                <Grid>                    

                    <Button x:Name="leftButton" Click="leftButtonClick" />

                    <Button x:Name="rightButton" />

                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>
Run Code Online (Sandbox Code Playgroud)

DoubleButton类如下所示:

public sealed class DoubleButton : Control
{
    public DoubleButton()
    {
        this.DefaultStyleKey = typeof(DoubleButton);
    }

    public void leftButtonClick(object sender, RoutedEventArgs e)
    {
        MessageDialog dlg = new MessageDialog("message");
    }
}
Run Code Online (Sandbox Code Playgroud)

但是这种方法永远不会被调用。如果有人对如何为自定义控件引发事件有个好主意。

谢谢

c# xaml windows-8 windows-runtime winrt-xaml

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

解释如何将VisualStateManager用于初学者

我知道很少Xaml/WPF.我正在尝试Style在Windows 8 metro应用程序中设计一个Button具有洋红色背景的自定义,并且在按下时,具有蓝色背景.我知道我需要使用VisualStateManager但我找不到任何在线对任何人有意义的东西对这个问题知之甚少.有很多假设的知识.这是我到目前为止所得到的:

<Style x:Name="test" TargetType="Button">
        <Setter Property="Background" Value="Magenta"/>
        <Setter Property="Content" Value="Test style" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Button">
                    <Grid>                          
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualState x:Name="Pressed">
                                    <Storyboard>
                                        <turn the background blue>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
Run Code Online (Sandbox Code Playgroud)

这段代码可能是非常错误的,但正如我所说,我一直试图修补一些我不理解的信息以创造结果.

感谢您的时间

wpf xaml microsoft-metro windows-8

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