问题列表 - 第44423页

C#在窗体上的某个位置获取控件

这是C#获取控件在窗体上的位置的反问题。

给定窗体内的Point位置,我如何找出在该位置用户可见的控件?

我目前正在使用HelpRequested表单事件来显示一个单独的帮助表单,如MSDN中所示:MessageBox.Show Method

在MSDN示例中,事件sender控件用于确定帮助消息,但sender在我的情况下,始终是表单而不是控件。

我想使用HelpEventArgs.MousePos来获取表单内的特定控件。

c# controls winforms

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

检查返回int的函数时出错

如果我有一个返回某种指针的函数,我会在错误时将返回值设置为NULL来检查错误.

char *foo(void) {
  //If stuff doesn't go okay
  return NULL;
}

char *bar = foo();
if(!bar) return 1;
Run Code Online (Sandbox Code Playgroud)

这很有效,因为我知道在这种情况下我永远不会想要返回NULL.

但是,有时候我会有返回整数的函数(在这种情况下,我从配置文件中读取int).但是,问题是现在无法检查返回的值是否有错误,因为任何值(包括0)都可能是真的.

一些解决方法:

  1. 在函数中包含错误代码参数
  2. 返回错误代码并包含int指针作为参数

这两个问题都是我有一组函数,它们都做同样的事情,但对于不同的类型,我想维护一个常规接口,以便它们可以以相同的方式使用.

是否有其他解决方案不涉及更改功能的接口?处理这种情况最常见的方法是什么?

选择解决方案

感谢您对此的所有想法和答案.

最后我决定,如果函数是为了返回某些数据,则只能通过error参数返回错误.否则,将直接返回错误.

我选择了这个根,因为通常我发现当返回更复杂的数据形式时,潜在错误的数量几乎总是大于1.这意味着使用NULL作为错误数据的唯一来源是不切实际的,因为它意味着没有确定错误实际是什么的方法.对于将数据作为int返回的函数,也不可能将多个不同的错误代码与有效数据区分开来.

当然,对于没有真正返回任何数据的函数,情况也是如此,在这种情况下,我可以自由地将返回值用作错误代码.

我也喜欢上述模式明确区分返回数据的函数和不返回数据的函数.

c error-handling

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

StringLengthAttribute似乎不起作用

这是我的带有数据注释的Test类:

class Test
{
  [Required, StringLength(10)]
  public string MyProperty { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

这是我的控制台测试程序:

class Program
{
  static void Main(string[] args)
  {
    var test = new Test {
      MyProperty = "this is way more than 10 characters and should fail."
    };

    var context = new ValidationContext(test, null, null);

    // No exception here! (why not?)
    Validator.ValidateObject(test, context);

    test.MyProperty = null;

    // Exception here, as expected
    Validator.ValidateObject(test, context);
  }
}
Run Code Online (Sandbox Code Playgroud)

出于某种原因,当字符串长度太长时,我没有得到验证异常.当我将属性设置为null并重新验证时,我确实得到了验证异常(如预期的那样).我的字符串长度注释没有被强制执行的任何想法?

validation ria data-annotations

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

处理大量的MKMapView注释

我有一个带有大量注释(3000+)的地图视图,当用户缩放到合理的水平时,一切都很好而且快速.

虽然当用户缩小并且大量注释进入视图时,由于一次显示大量注释,因此存在大量减速.处理这个问题的最佳方法是什么?

我正在使用的当前解决方案:

- (void)mapView:(MKMapView *)_mapView regionDidChangeAnimated:(BOOL)animated {

    NSArray *annotations = [_mapView annotations];  
    MapAnnotation *annotation = nil; 

    for (int i=0; i<[annotations count]; i++)
    {
        annotation = (MapAnnotation*)[annotations objectAtIndex:i];
        if (_mapView.region.span.latitudeDelta > .010)
        {
            [[_mapView viewForAnnotation:annotation] setHidden:YES];
            warningLabel.hidden = NO;
        }
        else {
            [[_mapView viewForAnnotation:annotation] setHidden:NO];
            warningLabel.hidden = YES;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

虽然由于环路的大小很大,但在放大和缩小以及滚动时会导致很多速度变慢.我似乎无法想到一个更好的方法来处理这个问题,有没有办法只循环当前正在显示的注释或沿着那些线的东西来减少循环的大小?

iphone objective-c mkmapview

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

PHP proc_open多次打开

我有一个实用程序函数用于通过CLI(cmd,bash等)执行程序.它返回的3项的数组:STDOUT,STDERREXIT CODE.

到目前为止,它一直很好地没有问题.事实上,我遇到的问题并没有真正阻碍它的功能,但我关注的是性能.

问题是在某些情况下,PHP会多次运行相同的命令(在我的情况下是3次),即使它只应该执行一次.

/**
 * Executes a program and waits for it to finish, taking pipes into account.
 * @param string $cmd Command line to execute, including any arguments.
 * @param string $input Data for standard input.
 * @param boolean $log Whether to log execution failures or not (defaults to true).
 * @return array Array of "stdout", "stderr" and "return".
 */
public static function execute($cmd,$stdin=null,$log=true){
    //static $once=true; if(!$once)die; $once=false;
    $proc=proc_open($cmd, array(
        0=>array('pipe','r'),
        1=>array('pipe','w'), …
Run Code Online (Sandbox Code Playgroud)

php windows proc-open command-line-interface k2f

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

WPF是否适用于C++?

我的理解是Microsoft Visual Studio被重写为使用WPF.我仍然不清楚为什么,但承认我对WPF的了解非常有限.

我的问题是,是否有人知道WPF对C++有多少支持,以及Visual Studio是否仍然用C++编写.

就个人而言,WPF主要似乎是.NET/VB/C#的东西.是否有人使用它与C++?

c++ wpf visual-studio

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

Python IDLE:更改Python版本

我的机器上有Python 2.x和3.x(Mac OS X 10.6).对于某些我想要使用版本2的东西,但对于其他我想要版本3.我喜欢IDLE软件进行编辑/运行,但它总是使用版本3.

有没有办法更改IDLE使用的解释器版本?

谢谢!

python editor version python-idle

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

验证:如何使用Ninject注入模型状态包装器?

我正在查看本教程http://asp-umb.neudesic.com/mvc/tutorials/validating-with-a-service-layer--cs,了解如何围绕包装器包装我的验证数据.

我想使用依赖注入.我正在使用ninject 2.0

namespace MvcApplication1.Models
{
    public interface IValidationDictionary
    {
        void AddError(string key, string errorMessage);
        bool IsValid { get; }
    }
}
Run Code Online (Sandbox Code Playgroud)

//包装

using System.Web.Mvc;

namespace MvcApplication1.Models
{
    public class ModelStateWrapper : IValidationDictionary
    {

        private ModelStateDictionary _modelState;

        public ModelStateWrapper(ModelStateDictionary modelState)
        {
            _modelState = modelState;
        }

        #region IValidationDictionary Members

        public void AddError(string key, string errorMessage)
        {
            _modelState.AddModelError(key, errorMessage);
        }

        public bool IsValid
        {
            get { return _modelState.IsValid; }
        }

        #endregion
    }
}
Run Code Online (Sandbox Code Playgroud)

//控制器

private IProductService _service;

public ProductController() 
{ …
Run Code Online (Sandbox Code Playgroud)

c# ninject ioc-container modelstate asp.net-mvc-2

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

codeigniter无法加载库

我有一个问题,我无法在我的控制器中加载我的库:S

我收到此错误:消息:未定义属性:Profil :: $ profileWall

我的图书馆:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); 

class ProfileWall
{

    private $CI;

    public function __construct()
    {
        $this->CI =& get_instance();
    }

    public function wallShow()
    {
        $this->CI->load->model('profil_model');
        return $this->CI->profil_model->wallGet($this->CI->uri->segment(3));
    }
}
Run Code Online (Sandbox Code Playgroud)

和我的控制器

    function index()
    {
        $this->load->model('profil_model');
        $data['query'] = $this->profil_model->vis_profil($this->uri->segment(3)); 


        //Henter lib profilwall så man kan vise wall beskeder i profilen
        $this->load->library('profileWall');
        $data['queryWall'] = $this->profileWall->wallShow();



        $data['content'] = 'profil_view';
        $this->load->view('includes/template', $data);


}
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

load controller codeigniter

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

如何将Google地图变成图像?而不能用鼠标移动?

我的javascript代码是这样的:

var myOptions = {
            scrollwheel:false,
            zoom: 15,
            center: the_lat_long,
            mapTypeControl:false,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        };
Run Code Online (Sandbox Code Playgroud)

javascript jquery google-maps

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