小编use*_*963的帖子

可能的意外参考比较

我有以下代码,它会发出警告

可能的意外参考比较; 要获得值比较,请将左侧投射到"string"类型

if (lblStatus.Content == "ACTIVE")
{
  //Do stuff
}
else
{
  //Do other Stuff
}
Run Code Online (Sandbox Code Playgroud)

我假设警告是因为lblStatus.Content可能不一定总是字符串类型?

我已尝试使用以下各项修复它,但我仍然收到警告

if (lblStatus.Content.ToString() == "ACTIVE")
if ((string)lblStatus.Content == "ACTIVE")
if (lblStatus.Content === "ACTIVE")
Run Code Online (Sandbox Code Playgroud)

请问有人可以解释一下我仍然会收到警告的原因以及解决此问题的最佳实用方法吗?

c#

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

远程服务器返回错误:(403)禁止

我已经编写了一个可以运行数月的应用程序,在过去的几天里我只在安装的版本上收到了以下错误.

如果我在VS中运行源代码一切正常.此外,bin文件夹中的.exe工作正常.它只是生成错误的已安装版本,如果我重新编译并重新安装,我会得到相同的错误.

关于造成这种情况的原因我有点难过,希望能指点一下.它似乎是通过IE的WebRequest响应没有返回,但我很难过为什么它在VS中正常工作没有任何错误.是否有任何新的IE安全措施/政策可能导致此问题?

到目前为止我尝试过的事情包括:

  • 禁用所有AntiVirus和防火墙
  • 以管理员身份运行

例外情况:

Exception: System.Windows.Markup.XamlParseException: The invocation of the constructor on type 'XApp.MainWindow' that matches the specified binding constraints threw an exception. ---> System.Net.WebException: The remote server returned an error: (403) Forbidden.
   at System.Net.HttpWebRequest.GetResponse()
   at XApp.HtmlRequest.getHtml(Uri uri) in J:\Path\MainWindow.xaml.cs:line 3759
   at XApp.MainWindow.GetLinks() in J:\Path\MainWindow.xaml.cs:line 2454
   at XApp.MainWindow..ctor() in J:\Path\MainWindow.xaml.cs:line 124
   --- End of inner exception stack trace ---
   at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
   at System.Windows.Markup.WpfXamlLoader.LoadBaml(XamlReader xamlReader, Boolean skipJournaledProperties, …
Run Code Online (Sandbox Code Playgroud)

c#

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

无法直接启动具有类库的输出类型的项目

请有人可以解释为什么我得到这个错误以及如何解决它(或者我做错了什么!).我采取的步骤是

  1. http://www.codeproject.com/Articles/16859/AForge-NET-open-source-framework下载源代码
  2. 在VS2010中打开显示无法找到引用 在此输入图像描述

  3. 重新添加所有3个引用,PlayingCardRecognition\bin\Release因此不再发出警告 在此输入图像描述

  4. 当我尝试构建或运行时,我收到以下消息 在此输入图像描述

c#

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

按名称查找WPF控件

我找到了一些帮助,找到了引用C#编程的控件的最佳方法

如果我预先在XAML中包含一个标签并在其中命名,marketInfo那么在代码中我可以设置Tag类似的属性

marketInfo.Tag = timeNow;
Run Code Online (Sandbox Code Playgroud)

但是,我正在构建控件并使用类似的东西为每个名称分配名称

System.Windows.Controls.Label lbl = new System.Windows.Controls.Label();
lbl.Content = market.name + " - " + DateTime.Now.ToLocalTime().ToLongTimeString();
lbl.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Left;
lbl.Height = 40;
lbl.Name = @"_" + "marketInfo" + countMarket;
Run Code Online (Sandbox Code Playgroud)

如何从其他方法引用这些控件?我已经阅读了一些建议使用的帖子,visualtreehelper但这似乎需要循环控件才能找到特定的控件.有没有办法按名称访问控件以避免循环?

例如类似的东西

//pseudo code
SomeControl("_marketInfo5").Tag = timeNow;
Run Code Online (Sandbox Code Playgroud)

谢谢

c# wpf

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

单个文件仅使用File对象选择

MSDN 在这里有一个File对象的例子,它允许选择多个文件

<!DOCTYPE html>
<html>
  <head>
    <title>Acquiring File Information</title>  
    <style type="text/css">
      #alert {
        color: red;
        margin: 1em 0;
      }
    </style>  
    <script type="text/javascript">
      window.addEventListener('load', init, false);

      function init() {
        checkForFileApiSupport();
        document.getElementById('files').addEventListener('change', handleFileSelection, false);
      }

      function checkForFileApiSupport() {
        if (window.File && window.FileReader && window.FileList && window.Blob) {  
        // All the File APIs are supported.
        } 
        else {  
          document.getElementById('alert').innerHTML = "The File APIs are not fully supported in this browser.";
        }
      }

      function handleFileSelection(evt) {    
        var files = evt.target.files; // The files …
Run Code Online (Sandbox Code Playgroud)

javascript html5

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

使用FileReader读取文本文件

我编写了以下代码以尝试读取.txt文件的内容

<!DOCTYPE html>
<html>

<input type="file" id="files" name="file" />
<div id="container" style="height: 500px; min-width: 500px"></div>

<script>
    function handleFileSelect(evt) 
    {
        var files = evt.target.files; // FileList object

        // Loop through the FileList and render image files as thumbnails.
        for (var i = 0, f; f = files[i]; i++) 
        {

            var reader = new FileReader();
            reader.onload = (function(theFile) 
            {
                var contents = theFile.target.result;
                    var lines = contents.split('\n');

            })(f);

            reader.readAsText(f);
        }
    }

  document.getElementById('files').addEventListener('change', handleFileSelect, false);
</script>
</html>
Run Code Online (Sandbox Code Playgroud)

使用萤火虫我设置了一个休息时间var contents = theFile.target.result;但没有返回任何东西.谁能发现什么是错的? …

html javascript

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

如何访问代码中的html控件

我试图按照这个例子来验证凭证.但是,它使用asp:controls作为登录表单.

如果我使用html控件,那么可以应用CSS样式,例如

<div id="login">
<a href="#" id="lclose"></a>

        <form action="#" runat="server">
            <fieldset>
                <div class="frame">
                    <h4>Login</h4>
                    <small>Sign in to your account.</small>
                    <div class="clear"></div>
                    <input type="text" value="Username" class="input-text autoclear" />
                    <input type="password" value="Password" class="input-text autoclear"/>
                </div>

                <div class="separator"></div>

                <div>
                <input type="submit" value="Sign in" class="input-submit float-right" runat="server" onserverclick="LoginButton_Click"/>
                <a href="#" class="float-left">Forgot your password?</a>
                </div>

            </fieldset>
        </form>

</div>
Run Code Online (Sandbox Code Playgroud)

如何在代码后面的代码中访问用户名和密码?

protected void LoginButton_Click(object sender, EventArgs e)
{
    // Validate the user against the Membership framework user store
    if (Membership.ValidateUser(UserName.Text, Password.Text))
    {
        // Log the …
Run Code Online (Sandbox Code Playgroud)

c# asp.net

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

获取wpf组合框选择的值

如何从下面的示例中获取所选值(例如Option1)string.我在Google上尝试过大量的建议,但无法获得字符串.

XAML:

<ComboBox x:Name="selectOption" Text="Select Option" 
                 SelectionChanged="selectOption_SelectionChanged" 
                 SelectedValue="{Binding VMselectedOption, Mode=TwoWay}" >
    <ComboBoxItem Name="cbb1">Option1</ComboBoxItem>
    <ComboBoxItem Name="cbb2">Option2</ComboBoxItem>
    <ComboBoxItem Name="cbb3">Option3</ComboBoxItem>
</ComboBox>
Run Code Online (Sandbox Code Playgroud)

代码隐藏:

private void selectOption_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
   var selectedValue = selectOption.SelectedValue; 
}

//elsewhere in code
var test = viewModel.VMselectedOption;
Run Code Online (Sandbox Code Playgroud)

selectedValue和test都返回字符串" System.Windows.Controls.ComboBoxItem:Option1 "而不是" Option1 "

这应该是非常简单但我不能让这个工作或看到什么是错的?

c# wpf

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

如何在Excel中打开特定版本的Word 2007/2010

我安装了Word 2007和2010.我需要在Excel中打开Word,但我需要指定我需要在VBA中打开哪个版本.

我试过晚绑定

Dim wordApp2007 As Object
Dim wordApp2010 As Object

Set wordApp2007 = CreateObject("Word.Application.12")
wordApp2007.Visible = True
Set wordApp2010 = CreateObject("Word.Application.14")
wordApp2010.Visible = True
Run Code Online (Sandbox Code Playgroud)

但都打开Word 2010

我也尝试过使用早期绑定

Dim wordApp As Word.Application
Set wordApp2007 = New Word.Application
wordApp2007.Visible = True
Run Code Online (Sandbox Code Playgroud)

并设置对Word 12.0对象模型的引用,但这仍然打开Word 2010 在此输入图像描述

如果我使用注册每个版本的Word

"C:\Program Files\Microsoft Office\Office12\WINWORD.EXE" /regserver

"C:\Program Files\Microsoft Office\Office14\WINWORD.EXE" /regserver

然后注册的版本打开但我无法打开未注册的.

任何人都可以帮助并告诉我如何使用VBA在Excel中打开特定版本的Word?

谢谢

编辑:示例代码....

Option Explicit

Dim wordApp2007 As Word.Application

Sub Word_InfoEarly()
'early binding
Set wordApp2007 = New Word.Application
wordApp2007.Visible = True

    'other Stuff
    Stop

    wordApp2007.Quit
    Set wordApp2007 …
Run Code Online (Sandbox Code Playgroud)

excel vba ms-word excel-vba

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

使用Late Binding订阅事件

我可以在myOlApp使用早期绑定的"类模块"中使用以下内容订阅Outlook事件.

'**Class Module - clsOutlookHandler **
Public WithEvents myOlApp As Outlook.Application

Private Sub Class_Initialize()
    On Error Resume Next
    Set myOlApp = GetObject(, "Outlook.Application")
    If Err.Number = 429 Then
        Set myOlApp = CreateObject("Outlook.Application")
        Err.Clear
    End If
    On Error GoTo 0
End Sub
Run Code Online (Sandbox Code Playgroud)

为此,我需要确保检查Microsoft Outlook XX.X对象库的引用.

是否可以使用后期绑定订阅Outlook(或任何应用程序)事件?

我知道以下内容不起作用.VBA中有解决方法吗?

Public WithEvents myOlApp As Object
Run Code Online (Sandbox Code Playgroud)

excel outlook vba

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

标签 统计

c# ×6

excel ×2

javascript ×2

vba ×2

wpf ×2

asp.net ×1

excel-vba ×1

html ×1

html5 ×1

ms-word ×1

outlook ×1