小编dts*_*tsg的帖子

显示文本通知图标鼠标悬停

如何在c#的mouseicon上显示文本.由于ShowBalloonTip显示超时,如何在鼠标悬停时显示Notify图标上的文本?

c# notifyicon

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

TryParse() - 为什么这段代码返回0,结果不应为-1?

请参阅以下代码:

string test = "";
int output = -1;

if (int.TryParse(test, out output))
{
    Console.WriteLine("Parsed");
}

Console.WriteLine(output);
Run Code Online (Sandbox Code Playgroud)

TryParse()失败时,不应该跳过块,Console.WriteLine("Parsed")不调用和值output相同(-1)?

它正在回归 0

.net c# console tryparse

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

为什么在一个Combo中更改SelectedItem会更改所有其他Combos?

我用这种方式填充了组合框

foreach (Control c in this.Controls)
{
     if (c is ComboBox)
     {
         (c as ComboBox).DataSource = DataSet1.Tables[0];
         (c as ComboBox).DisplayMember = "Articles";
     }
}
Run Code Online (Sandbox Code Playgroud)

但是,问题是当我在一个组合中更改SelectedItem时 - 它在所有其他组合中变得更改了吗?

c# combobox winforms

8
推荐指数
3
解决办法
5348
查看次数

同一个kinect设备上的多个应用程序

可以使用多个使用相同kinect设备的应用程序吗?

.net c# kinect

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

在解析XDocument时处理null XElements

做这样的事情是否有更好的方法:

private XElement GetSafeElem(XElement elem, string key)
{
    XElement safeElem = elem.Element(key);
    return safeElem ?? new XElement(key);
}

private string GetAttributeValue(XAttribute attrib)
{
    return attrib == null ? "N/A" : attrib.Value;
}

var elem = GetSafeElem(elem, "hdhdhddh");
string foo = GetAttributeValue(e.Attribute("fkfkf"));

//attribute now has a fallback value
Run Code Online (Sandbox Code Playgroud)

从XML文档解析元素/属性值时?在某些情况下,在执行以下操作时可能找不到该元素:

string foo (string)elem.Element("fooelement").Attribute("fooattribute").Value
Run Code Online (Sandbox Code Playgroud)

因此会发生对象引用错误(假设未找到元素/属性).尝试访问元素值时相同

c# xml error-handling linq-to-xml

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

防止"点击"事件多次触发+褪色问题

早上好.我正在制作一个简单的jQuery画廊的问题.它允许用户通过一些按钮循环浏览一组图像,同时在计时器上旋转这些图像.我的问题是用户能够多次点击该按钮,将淡入淡出的动画排队并反复重复,例如用户点击按钮5次>相同图像淡入/淡出5次>图库移动到下一张图像.

我尝试过使用:

$('#homeGalleryImage li a').unbind('click');

触发click事件然后重新绑定后:

$('#homeGalleryImage li a').bind('click');

完成之后,这只是在按下一次按钮之后删除了点击事件并且从不重新绑定它?

我也试过通过以下方式禁用按钮:

$('#homeGalleryImage li a').attr('disabled', true);

无济于事......?

还有一个次要问题,如果您在图像处于转换状态时设置单击按钮,则下一个图像显示为"淡化",就像不透明度已降低一样?很奇怪......以下是按钮点击的代码:

var i = 1;
var timerVal = 3000;
$(function () {
    $("#homeGalleryControls li a").click(function () {
        var image = $(this).data('image');
        $('#galleryImage').fadeOut(0, function () {
            $('#galleryImage').attr("src", image);
        });
        $('#galleryImage').fadeIn('slow');
        $('.galleryButton').attr("src", "/Content/Images/Design/btn_default.gif");
        $(this).find('img').attr("src", "/Content/Images/Design/btn_checked.gif");
        i = $(this).data('index') + 1;
        if (i == 4) {
            i = 0;
        }
        timerVal = 0;
    });
});
Run Code Online (Sandbox Code Playgroud)

以下是在计时器上循环显示图像的代码:

//Cycle through gallery images on a timer
window.setInterval(swapImage, timerVal);
function swapImage() …
Run Code Online (Sandbox Code Playgroud)

html javascript css jquery gallery

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

参数字典包含非可空类型的参数"id"的空条目

我正在尝试通过id默认路由中的参数从我的数据库中检索数据:

routes.MapRoute(
            "Default", // Route name
            "{controller}/{action}/{id}", // URL with parameters
            new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
        );
Run Code Online (Sandbox Code Playgroud)

在这个ActionResult中,我试图基于route id参数呈现自定义用户控件,以便检索所请求页面的相关数据

public ActionResult InitPageNav(int id)
{
      PageModel page = PageNavHelper.GetPageByID(id);
      return PartialView("UserControls/_PageNavPartial", page);
}
Run Code Online (Sandbox Code Playgroud)

编辑*

public static MvcHtmlString CreateMenuItems(this HtmlHelper helper, string action, string text)
{
     var menuItem = new TagBuilder("li");
     var link = new TagBuilder("a");

     //Get current action from route data
     var currentAction = (string)helper.ViewContext.RouteData.Values["action"];
     link.Attributes.Add("href", string.Format("/Home/{0}", action));

     if …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc routes actionresult

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

正则表达式验证字母数字字符串的长度

我有以下正则表达式:

^[a-zA-Z0-9]+( [a-zA-Z0-9]+)*$
Run Code Online (Sandbox Code Playgroud)

我正在尝试验证0到10个字符之间的字符串,该字符串不能包含更多行中的两个空格或不能为空.该字符串不能包含任何特殊字符,并且可以不区分大小写,并且可以包含连字符.

如何将输入限制在0-10个字符之间?

我试过了

^[a-zA-Z0-9]+( [a-zA-Z0-9]+{0,10})*$
Run Code Online (Sandbox Code Playgroud)

但它不起作用.

.net c# regex validation alphanumeric

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

另一个控制器内的MVC控制器?

我想知道是否有可能在MVC 3中的一个主要控制器中有几个嵌套控制器?例如:

public class AdminController : Controller
{
    public class PagesController : Controller
    {
    }
    //More controllers
}
Run Code Online (Sandbox Code Playgroud)

我试过这个但是无法让它工作,修改了我在global.asx中的路由,但仍然没有.如何AdminController在网址为例时调用正确的控制器:

/Admin/Pages/Index

c# asp.net-mvc controller

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

为什么我找不到面板中继器项目?

Object reference not set to an instance of an object当我试图找到一个Panel控件时,我一直收到错误Repeater.但其他控制措施都很好吗?谁能看到这里有什么问题?

这就是我选择控件的方式:

Panel pnlSubCategories = (Panel)e.Item.FindControl("pnlSubCategories");
Run Code Online (Sandbox Code Playgroud)

标记:

<asp:Repeater ID="rptInnerCategories" runat="server" OnItemDataBound="rptCategories_OnItemDataBound">
  <ItemTemplate>
       <li id="liCategory" runat="server">
           <asp:HyperLink ID="lnkCategory" runat="server">
                <span><asp:Literal ID="litCategory" runat="server" Visible="true" /></span>
                <asp:Image ID="imgMan" runat="server" Visible="false" /></asp:HyperLink>

                <asp:Panel ID="pnlSubCategories" runat="server" Visible="false">
                  <ul>
                     <asp:Repeater ID="rptSubCategories" runat="server" Visible="false" OnItemDataBound="rptSubCategories_OnItemDataBound">
                      <ItemTemplate>
                        <li id="liSubCategory" runat="server">
                         <asp:HyperLink ID="lnkSubCategory" runat="server">
                          <span><asp:Literal ID="litSubCategory" runat="server" /></span></asp:HyperLink>
                        </li>
                       </ItemTemplate>
                      </asp:Repeater>
                  </ul>
                 </asp:Panel>
        </li>            
   </ItemTemplate>
</asp:Repeater>
Run Code Online (Sandbox Code Playgroud)

代码背后:

if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem)) …
Run Code Online (Sandbox Code Playgroud)

c# asp.net controls repeater panel

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