我在Canvas中有一个Shape ,像这样:
<ScrollViewer>
<Border Height="342" Width="470" HorizontalAlignment="Left"
VerticalAlignment="Top" BorderThickness="3" BorderBrush="Black">
<Canvas Background="White">
<Rectangle Width="200" Height="200" Canvas.Left="103"
Canvas.Top="186" Fill="Red" />
</Canvas>
</Border>
</ScrollViewer>
Run Code Online (Sandbox Code Playgroud)
即使Rectangle是Canvas的孩子,它也会在Canvas限制之外绘制,覆盖边框底部边框.如何使Rectangle仅在Canvas限制内绘制,确保不显示超出矩形的部分?
谢谢.
我有一个形状(下面的红色路径),我必须在这个路径上应用TranslateTransform和ScaleTransform转换.但是如果我以这种方式使用Shape RenderTransform属性:
Path MyPath = new Path { Fill = new SolidColorBrush(Colors.Red) };
MyPath.Data = MyPathGeometry;
TransformGroup transf = new TransformGroup();
transf.Children.Add(new TranslateTransform(50, 50));
transf.Children.Add(new ScaleTransform(2, 2));
MyPath.RenderTransform = transf;
Run Code Online (Sandbox Code Playgroud)
我得到了这种类型的图纸:

相反,如果我以这种方式使用DrawingContext PushTransform方法:
DrawingVisual MyPath = new DrawingVisual();
using (DrawingContext context = MyPath.RenderOpen()) {
context.PushTransform(new TranslateTransform(50, 50));
context.PushTransform(new ScaleTransform(2, 2));
context.DrawGeometry(Brushes.Red, null, MyPathGeometry);
}
Run Code Online (Sandbox Code Playgroud)
我得到了这种类型的图纸:

为什么这两条路径以不同的方式放置?使用PushTransform和RenderTransform有什么区别?在两种情况下我怎么能得到相同的结果?谢谢.
我有我的课,我重载了!操作员:
class obj
{
public:
bool operator!() const
{ return this->str.length() == 0; }
private:
string str;
};
Run Code Online (Sandbox Code Playgroud)
对于!运营商我想检查obj有效性,所以:
obj o;
// if o is not a valid object
if(!o)
cerr << "Error";
Run Code Online (Sandbox Code Playgroud)
现在我希望有可能这样做:
// if o is a valid object
if(o)
cout << "OK";
Run Code Online (Sandbox Code Playgroud)
我能怎么做?
我有以下代码,我开始Thread使用一个ParameterizedThreadStart对象作为构造函数参数:
static object obj = new object();
static void Main(string[] args)
{
ParameterizedThreadStart start = (o) =>
{
ThreadTest(o);
};
var t = new Thread(() => start(obj));
t.Name = "t";
t.Start();
Thread.Sleep(3000);
obj = null;
// Why the Thread (t) continue here??
Console.ReadKey();
}
private static void ThreadTest(object o)
{
while (o != null)
{
Console.WriteLine(Thread.CurrentThread.Name);
Thread.Sleep(1000);
}
}
Run Code Online (Sandbox Code Playgroud)
之后,我设置obj到null在ThreadTest方法的参数o仍然是一个有效的对象,为什么呢?
如何设置参数o来null使用obj?
我有我的C列表,我实现了这个push_back功能:
bool_t push_back_clist(clist_ptr pList, void* item)
{
if(pList)
{
node_ptr pNode = new_node(item, pList->sizeof_item);
if(!pNode) return FALSE;
if(!pList->head)
pList->head = pList->tail = pNode;
else
{
pList->tail->next = pNode;
pNode->prev = pList->tail;
pList->tail = pNode;
}
pList->size++;
return TRUE;
}
return FALSE;
}
static node_ptr new_node(void* data, size_t sizeof_item)
{
node_ptr pNode = (node_ptr) malloc(sizeof(node_t));
if(!pNode) return NULL;
pNode->data = malloc(sizeof_item);
if(!pNode->data)
{
free(pNode);
return NULL;
}
memcpy(pNode->data, data, sizeof_item);
pNode->next = pNode->prev = NULL;
return pNode;
}
Run Code Online (Sandbox Code Playgroud)
它有效,但是当我将我的 …
是否可以在同一个catch块中捕获多个异常?
try
{ }
catch(XamlException s | ArgumentException a)
{ }
Run Code Online (Sandbox Code Playgroud) 我需要在C#项目中使用C库.我能怎么做?
更具体一点:出于效率原因,我需要使用strtod函数从字符串中提取双值(如"9.63074,9.63074 -5.55708e-006 0,01477.78").如果您有关于如何优化此操作的建议,请不要害羞,但主要问题仍然是标题指定.
让我们说我定义一个宏:
#define MAX(x,y) ((x)>(y)?(x):(y))
Run Code Online (Sandbox Code Playgroud)
如果我打电话MAX(I++,J++)会怎么样?
我无法理解为什么答案不会像预期的那样.