c#中通知属性更改项目字段的最佳方法是什么,set但get取决于其他字段?
例如 :
public class Example : INotifyPropertyChanged
{
private MyClass _item;
public event PropertyChangedEventHandler PropertyChanged;
public MyClass Item
{
get
{
return _item;
}
protected set
{
_item = value;
OnPropertyChanged("Item");
}
}
public object Field
{
get
{
return _item.Field;
}
}
#if !C#6
protected void OnPropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
#else
protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new …Run Code Online (Sandbox Code Playgroud) 我正在寻找一种方法来识别 C# 中的图像是否模糊。我看到了这篇文章,但我没有看到适用于我的案例的方法。
我找到了AForge.dll将 FFT 应用于我的图像。我正在寻找一种简单的方法来确定图像是否模糊(我对数学不太熟悉)。
这是我的代码:
Bitmap Picture;
// I'm working with images sized between 130x130 and 150x150
Bitmap tmp = new Bitmap(pictureFile);
// Crop to be 128x128
Bitmap cropped = cropBitmap(tmp, 128, 128);
using (MemoryStream ms = new MemoryStream())
{
cropped.Save(ms, ImageFormat.Gif);
ms.Position = 0;
// Save in grayscale
Picture = new Bitmap(ms);
}
// Create the ComplexImage with AForge.dll
ComplexImage output = ComplexImage.FromBitmap(Picture);
// Apply FFT
output.ForwardFourierTransform();
Bitmap result = output.ToBitmap();
// to …Run Code Online (Sandbox Code Playgroud) 是否可以使用预处理程序指令检测当前版本的C#是否为6或更高,因此在编译时?
我想做这样的事情:
var myVar = ...;
string name;
#if VERSION_6_OR_MORE
name = nameof(myVar);
#else
name = "myVar";
#endif
Run Code Online (Sandbox Code Playgroud)
我使用Visual Studio 2015和C#6,所以我可以使用nameof().其他想要编译此代码的人可能正在使用旧版本,但nameof()不存在.
我想使用预处理器指令,所以我可以保留nameof()在C#6中,但是不使用该版本的其他人也可以编译它.
我正在研究 c# WinForm。
我有一个自定义的 UserControl : MyControl : UserControl, INotifyPropertyChanged。我在 VisibleChanged 事件上附加了一个方法:this.VisibleChanged += new System.EventHandler(this.MyControl_VisibleChanged);
我的应用程序有一些页面,每个页面都是一个像MyControl. MainWindows 顶部包含按钮,用于切换选项卡。
我的问题是,MyControl_VisibleChanged仅当 Visible 更改为 true 时才调用我的函数。我在一个选项卡中添加了一个测试来检查MyControl.Visible,当我选择另一个选项卡时,MyControl.Visible但false没有引发任何事件。
我尝试为此控件定义一个新属性 Visible,但从未设置值,仅base修改值。
你能帮我找到解决方案吗?
这是我第一次尝试为Android/iOS创建库c ++.
我正在使用Visual Studio 2015 - Xamarin.
首先,我创建了一个项目:Visual C++ - >跨平台 - >共享库.在hared库中,我创建了2个文件.
SayHello.h:
#pragma once
#include <string.h>
class SayHello {
public:
SayHello();
~SayHello();
static char* Hello();
};
Run Code Online (Sandbox Code Playgroud)
SayHello.cpp:
#include "SayHello.h"
extern "C"
{
SayHello::SayHello(){}
SayHello::~SayHello(){}
char * SayHello::Hello()
{
return "Hello !";
}
}
Run Code Online (Sandbox Code Playgroud)
然后我生成了一个文件libSayHello.so并用xamarin创建了一个Android项目来尝试调用函数hello.有我的MainActivity.cs:
[DllImport("libSayHello.so")]
static extern String Hello();
protected override void OnCreate(Bundle bundle)
{
// I paste only my added code :
String hello = Hello();
Toast.MakeText(this.ApplicationContext, hello, ToastLength.Long);
}
Run Code Online (Sandbox Code Playgroud)
我完成了本教程中的所有步骤,但我有一个例外:
System.DllNotFoundException:libSayHello.so
我搜索了这个,但我一定是那么的菜鸟,因为我没找到任何东西.我应该如何使用我的 …
在C#中我有(用Visual Studio监视工具看到):
float.MinValue = -3.40282347E+38
Run Code Online (Sandbox Code Playgroud)
在C++中:
std::numeric_limits<float>::min() = 1.17549435e-038
Run Code Online (Sandbox Code Playgroud)
为什么价值观不一样?我怎样才能-3.40282347E+38在C++中得到(C#值)?
我看到了很多与此相关的主题,我了解了理论,但无法对此进行编码。
我有一些图片,我想确定它们是否模糊。我找到了一个库(aforge.dll),并用它来对图像进行FFT 运算。
例如,我正在处理两个图像:
我的代码在c#中:
public Bitmap PerformFFT(Bitmap Picture)
{
//Loade Image
ComplexImage output = ComplexImage.FromBitmap(Picture);
// Perform FFT
output.ForwardFourierTransform();
// return image
return = output.ToBitmap();
}
Run Code Online (Sandbox Code Playgroud)
如何确定图像是否模糊?我对理论不太满意,我需要具体的例子。我看到了这篇文章,但我不知道该怎么做。
编辑:
我会澄清我的问题。当我有一个复数的2D数组ComplexImage output(图像FFT)时,可以使用什么C#代码(或伪代码)来确定图像是否模糊?
如何更改文本框上的自动完成功能?我希望当我输入一个字符串时,该框会建议包含该字符串的项目,而不是以它开头。
我的代码是:
class MyClass
{
private AutoCompleteStringCollection autoCompleteList = new AutoCompleteStringCollection();
public MyClass()
{
InitializeComponent();
autoCompleteList.AddRange(ListNames.Select(x=>x.Name).ToArray());
textBoxName.AutoCompleteCustomSource = autoCompleteList;
textBoxName.AutoCompleteSource = AutoCompleteSource.CustomSource;
textBoxName.AutoCompleteMode = AutoCompleteMode.Suggest;
textBoxName.KeyDown += TextBoxtextName_KeyDown;
}
private void TextBoxClient_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyData == Keys.Enter)
{
this.Name = (sender as TextBox).Text;
}
}
}
Run Code Online (Sandbox Code Playgroud)
我想要的是:
我有以下代码:
typedef signed char Char;
static const struct MyStruct
{
const Char* str;
// Other fields
}
myList[] =
{
{"none", /* Other fields */},
{"main", /* Other fields */},
}
Run Code Online (Sandbox Code Playgroud)
但我有编译错误:
无法使用类型为“const char [X]”的左值初始化“const Char *”(又名“const signed char *”)类型的成员子对象
X 是字符串长度
当我替换为时就可以Char了char,但是我该如何使用signed char呢?
我正在将C#的一部分代码翻译成C++.
以下是我的观点:
Class Point
{
public int X;
public int Y;
}
const int MAX = 256;
public void ComputePoints(Byte[] image,
int width,
int height,
out List<Point>[] listPixels)
{
listPixels = new List<Point>[MAX];
//etc..
}
Run Code Online (Sandbox Code Playgroud)
(我简化了这段代码只显示有趣的部分).
我的问题关注的是out List<Point>[] listPixels.我试着通过以下方式翻译:
public void ComputePoints(unsigned char[] image,
int width,
int height,
std::vector<Point> *listPixels[])
{
*listPixels = new std::vector<Point>[MAX];
//etc..
}
Run Code Online (Sandbox Code Playgroud)
但我有错误
分段故障.
如何out List<Point>[] listPixels在C++中编写最简单的等价物?
c# ×8
c++ ×4
fft ×2
image ×2
winforms ×2
aforge ×1
android ×1
autocomplete ×1
textbox ×1
visibility ×1