小编Ove*_*Ove的帖子

检查点是否在旋转的矩形中(C#)

我有一个C#程序(Windows窗体),它在一个图片框上绘制一些矩形.它们也可以以一定角度绘制(旋转).

我知道每个矩形的起点(左上角),它们的大小(宽度+高度)和它们的角度.由于旋转,起点不一定是左上角,但这并不重要.然后当我点击图片框时,我需要检查我点击了哪个矩形(如果有的话).

所以我需要一些检查点是否在矩形中的方法,但我还需要考虑每个矩形的旋转.有人知道在C#中这样做的方法吗?

c# math graphics geometry

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

团队成员未在VS2013中展示

我试图从2010年切换到Visual Studio 2013.

我在VS2010中使用的一个功能是Team Explorer窗格中的Team Members列表.该功能未包含在Visual Studio中,但包含在我已安装的Team Foundation Server 2010 Power Tools中.

现在我已经安装了VS2013以及Team Foundation Server 2013 Power Tools,但我在VS2013中没有看到Team Members列表.

如何让团队成员列表显示在VS2013中?

以下是我的团队资源管理器窗格在VS 2013和VS 2010中的外观: Team explorer 2013 vs 2010

tfs-power-tools visual-studio-2013

11
推荐指数
1
解决办法
2974
查看次数

如何在ListView中为不可见(虚拟化)项绑定IsSelected

我需要处理WPF应用程序中的大量数据.

我已将大型集合绑定到ListView,并且我使用ItemContainerStyle将列表项的IsSelected属性绑定到我的对象的IsSelected属性,以便在选中该项时ListView,my objects的IsSelected属性也将设置为true.通过这样做,我可以轻松地仅对列表中已选择的对象执行命令.

我在ListView中使用UI虚拟化,因为应用程序会缓慢.但是因为我的整个集合中只有一部分在列表中可见,所以当我使用CTRL + A选择列表中的所有项目时,只有加载的项目的IsSelected属性设置为true.不可见的项目(虚拟化的项目)的IsSelected属性设置为false.这是一个问题,因为当我选择列表中的所有项目时,我希望该IsSelected属性对于集合中的所有项目都设置为true.

我已经创建了一些示例代码来说明问题:

MainWindow.xaml

<Window x:Class="VirtualizationHelp.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525" x:Name="wnd">
<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition/>
    </Grid.RowDefinitions>
    <Button Grid.Row="0" Content="Click me" Click="Button_Click" />
    <ListView Grid.Row="1" ItemsSource="{Binding Path=Persons, ElementName=wnd}">
        <ListView.ItemContainerStyle>
            <Style TargetType="{x:Type ListViewItem}">
                <Setter Property="IsSelected" Value="{Binding Path=IsSelected, Mode=TwoWay}"/>
            </Style>
        </ListView.ItemContainerStyle>
    </ListView>
</Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)

MainWindow.xaml.cs

using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;

namespace VirtualizationHelp
{
    public partial class MainWindow : Window
    { …
Run Code Online (Sandbox Code Playgroud)

wpf virtualization ui-virtualization

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

Android selectableItemBackground长按没有发光效果

我想在Android应用程序中使用RecyclerView.我将RecyclerView示例项目导入Android Studio,它运行正常.

我想让回收者视图中的项目在用户长时间按下时进行视觉反应.为此,我将视图的背景设置为selectableItemBackground.我做了这些修改:

  • 在text_row_item.xml中,我在FrameLayout标记上添加了这一行:

    android:background="?android:attr/selectableItemBackground"

  • 在CustomAdapter.java中,我在FrameLayout上添加了一个长按侦听器:

    v.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View view) { Log.d(TAG, "Element " + getPosition() + " long clicked."); return true; } });

如果我在Lollipop仿真器上运行修改后的样本,当我长按回收器视图中的项目时,我会得到很好的涟漪效果.

但是如果我在KitKat模拟器上运行应用程序,我就不会获得KitKat附带的发光效果.当我长按它时,列表中的项目变得更暗,并且长按聆听器确实会运行,但我预计在长时间按下时颜色会发光.

这是我正在发布的一个gif: 长按动画无效

为什么selectableItemBackground不在KitKat上运行发光效果?如何让它在KitKat和Lollipop上运行?

android android-recyclerview

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

在OpenCV中创建AVI文件

我一直在尝试使用OpenCV和Visual Studio 2008创建应用程序,从网络摄像头捕获图像,对它们应用过滤器,然后将它们写入AVI文件.除了创建AVI文件外,一切正常.

问题是它可以在我的计算机上运行,​​但它不能在我同事的计算机上运行.之所以(我认为)是因为他没有必要的视频编码器供OpenCV使用.

cvCreateVideoWriter函数不返回NULL,但我最终在磁盘上有一个0kb文件.

video opencv

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

WPF一个像素宽的线有时会消失

我正在尝试制作一个在其中心绘制红十字的控件.我希望十字形是一个像素宽,我想禁用抗锯齿并使其捕捉到屏幕的像素.

该控件有效,但是如果我将其添加到具有分割器的Grid中,当我拖动分割器时,其中一条线有时会消失.如果我把它放在带有水平分割器的网格内,水平线有时会消失,如果我把它放在带有垂直分割器的网格内,垂直线有时会消失.

怎么能阻止线条消失?

这是xaml代码:

<Window x:Class="WpfTest.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:WpfTest"
        Title="MainWindow" Height="600" Width="800">
    <Window.Resources>
        <local:HalfValueConverter x:Key="halfConv" />

        <Style TargetType="Line">
            <Setter Property="Stroke" Value="Red"/>
            <Setter Property="StrokeThickness" Value="1"/>
            <Setter Property="RenderOptions.EdgeMode" Value="Aliased"/>
            <Setter Property="SnapsToDevicePixels" Value="True" />
        </Style>
    </Window.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <Grid Grid.Row="2" Background="Black" Name="grdParent">
            <Line X1="{Binding ActualWidth, ElementName=grdParent, Converter={StaticResource halfConv}}"
              Y1="0" 
              X2="{Binding ActualWidth, ElementName=grdParent, Converter={StaticResource halfConv}}"
              Y2="{Binding ActualHeight, RelativeSource={x:Static RelativeSource.Self}}"
              Height="100"
              />
            <Line X1="0" 
              Y1="{Binding ActualHeight, ElementName=grdParent, Converter={StaticResource halfConv}}"
              X2="{Binding ActualWidth, RelativeSource={x:Static RelativeSource.Self}}"
              Y2="{Binding ActualHeight, ElementName=grdParent, Converter={StaticResource halfConv}}" …
Run Code Online (Sandbox Code Playgroud)

c# wpf

6
推荐指数
1
解决办法
1023
查看次数

遍历IP地址

假设我有两个IP地址(在.NET中,System.Net.IPAddress该类)。如何在两个给定地址之间迭代所有IP地址?

例如,让一个地址为192.168.1.1,另一个地址为192.168.2.3。我想以某种方式遍历它们之间的所有地址,并将它们打印到控制台。

谢谢。

.net c#

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

WPF 忽略弹出窗口之外的点击

在我的 WPF 应用程序中,我想在单击按钮时显示一个弹出窗口。

如果我在弹出窗口外单击,我希望关闭弹出窗口。我可以通过StaysOpen=False在弹出窗口上进行设置来完成此操作。

但是当我在弹出窗口外单击时,我希望 WPF 忽略关闭弹出窗口的初始单击。例如,如果我在弹出窗口外单击另一个按钮,我不希望该按钮执行 click 方法。

如何让 WPF 在弹出窗口打开时忽略弹出窗口外的点击?

这是一些示例代码。当我单击“弹出”按钮时弹出窗口打开,当我单击外部时它关闭。但是我可以在弹出窗口打开时单击“PrintMessage”按钮,它的单击事件将触发。我希望它的点击事件不要触发。

<Window x:Class="Test.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Window.Resources>
        <Popup x:Key="pop" StaysOpen="False" Placement="MousePoint">
            <UniformGrid Background="Red">
                <Button>Btn1</Button>
                <Button>Btn2</Button>
            </UniformGrid>
        </Popup>
    </Window.Resources>
    <UniformGrid>
        <Button Click="Popup_Click">Popup</Button>
        <Button Click="PrintMessage_Click">PrintMessage</Button>
    </UniformGrid>
</Window>

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
    }

    private void Popup_Click(object sender, RoutedEventArgs e)
    {
        Popup pop = (Popup)Resources["pop"];
        pop.IsOpen = true;
    }

    private void PrintMessage_Click(object sender, RoutedEventArgs e)
    {
        Debug.WriteLine("Test");
    }
}
Run Code Online (Sandbox Code Playgroud)

c# wpf popup

5
推荐指数
0
解决办法
367
查看次数

C++认为'<<'不是类的成员,但它是

我必须编写一个简单的日志类,将输出写入文件.

我希望它能够重载<<运算符,所以我可以这样做:

MyLog log("C:\\log.txt");
log<<"Message";
Run Code Online (Sandbox Code Playgroud)

但Visual C++告诉我:"错误C2039:'<<':不是'MyLog'的成员"

我不知道我做错了什么.

这是代码:

MyLog.h

#pragma once
#include <iostream>
#include <conio.h>
#include <fstream>
using namespace std;

class MyLog
{
private:
    ofstream logfile;
public:
    MyLog(char* filename);
    friend MyLog& operator<<(MyLog& l,char*msg);
};
Run Code Online (Sandbox Code Playgroud)

MyLog.cpp

#include "MyLog.h"

MyLog::MyLog(char* filename)
{
    logfile.open(filename);
}

MyLog& MyLog::operator<<(MyLog& l,char*msg)
{
    cout<<msg;
    return l;
}
Run Code Online (Sandbox Code Playgroud)

有谁知道什么是错的?

c++ operator-overloading

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

在EPD上安装Theano(Windows x64)

我正在尝试在Enthought Python Distribution(EPD)上安装Theano,但我得到了一个奇怪的错误.这是我的安装的样子:

  • 我已经安装了EPD C:\Python27.
  • 在那之后,我已经安装pip了使用easy_install pip
  • 我使用安装了Theano pip install Theano
  • 为了测试,我开始ipython并输入import theano.我收到以下错误:

    Problem occurred during compilation with the command line below:
    g++ -shared -g -IC:\Python27\lib\site-packages\numpy\core\include -IC:\Python27\include -o C:\Users\Ove\AppData\Local\Theano\compiledir_Windows-7-6.1.7601-SP1-Intel64_Family_6_Model_37_Stepping_5_GenuineIntel-2.7.2\lazylinker_ext\lazylinker_ext.pyd C:\Users\Ove\AppData\Local\Theano\compiledir_Windows-7-6.1.7601-SP1-Intel64_Family_6_Model_37_Stepping_5_GenuineIntel-2.7.2\lazylinker_ext\mod.cpp -LC:\Python27\libs -LC:\Python27 -lpython27
    C:\Users\Ove\AppData\Local\Temp\ccIoNPlU.o: In function `initlazylinker_ext':C:/Users/Ove/AppData/Local/Theano/compiledir_Windows-7-6.1.7601-SP1-Intel64_Family_6_Model_37_Stepping_5_GenuineIntel-2.7.2/lazylinker_ext/mod.cpp:911: undefined reference to `__imp_Py_InitModule4'
    collect2: ld returned 1 exit status
    
    Exception: Compilation failed (return status=1): C:\Users\Ove\AppData\Local\Temp. C:/Users/Ove/AppData/Local/Theano/compiledir_Windows-7-6.1.7601-SP1-Intel64_Family_6_Model_37_Stepping_5_GenuineIntel-2.7.2/lazylinker_ext/mod.cpp:911: undefi. collect2: ld returned 1 exit status4'
    
    Run Code Online (Sandbox Code Playgroud)

有谁知道如何让Theano与EPD合作?

python windows enthought theano

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

在openCV中使用imshow函数

我正在使用imshow函数在OpenCV中显示图像.它工作正常,但只有一点点:我为图像写的标题没有正确显示.

例如,当我写"原始"或"倒置"时,它们会在开头显示一些额外且难以理解的数据.但是,当我写"阈值图像"时,会显示一长串难以理解的单词,而不是标题...

它没有任何其他影响,但它似乎对我来说很奇怪.你知道为什么会这样吗?

这是我的代码:

IplImage* image=cvLoadImage("Black&White.jpg");
Mat image1;
image1=Mat(image,false);
imshow("Image",image1);
cvWaitKey(0);
Run Code Online (Sandbox Code Playgroud)

c++ opencv

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

WPF中的陷阱鼠标

我有一个画布,我有一个图像.我可以使用鼠标移动该图像(拖放).我想阻止用户将图像移到画布之外.

有什么方法可以捕获鼠标指针,使它只能在画布内移动吗?因此,当用户尝试将鼠标移动到画布外时,光标将保留在画布的边缘.

此行为的一个示例是移动窗口时,您无法在任务栏上移动它.当您尝试在任务栏上移动它时,鼠标光标停留在任务栏的边缘,拒绝移动任务栏顶部.

c# wpf mouse

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

未调用Dispose和Finalizer,发生OutOfMemoryException

我正在尝试编写一个包含分配的缓冲区的类Marshal.AllocHGlobal.我实现了IDisposable接口,并添加了一个终结器,当我不再需要它时(当对象超出范围时)应释放内存.

当我测试类时,GC不会调用我的类的终结器或Dispose方法,即使它们超出了范围.结果,我得到了一个OutOfMemoryException.

为什么GC不会调用终结器,为什么内存不会被释放?

这是一个简短的例子来说明问题.在示例中,没有任何内容写入控制台(除外Unhandled Exception: OutOfMemoryException.)

class Buffer : IDisposable
{
    public IntPtr buf { get; set; }

    public Buffer()
    {
        buf = Marshal.AllocHGlobal(4 * 1024 * 1024);
    }

    ~Buffer()
    {
        Console.WriteLine("Finalizer called");
        Dispose(false);
    }

    public void Dispose()
    {
        Console.WriteLine("Dispose called");
        Dispose(true);
        GC.SuppressFinalize(this);
    }

    internal virtual void Dispose(bool disposing)
    {
        if (buf != IntPtr.Zero)
        {
            Console.WriteLine("Releasing memory");
            Marshal.FreeHGlobal(buf);
            buf = IntPtr.Zero;
        }
    }
}

class Program
{
    static void Main(string[] args)
    { …
Run Code Online (Sandbox Code Playgroud)

c# memory garbage-collection

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