我需要一些用户控件的帮助。 我有一个具有自定义ControlDesigner的用户控件:
在设计器中,如果我在用户控件上更改了特定属性,我会更改SelectionRules。
我遇到的问题如下: 当我放置此用户控件的多个副本并更改属性时,设计器将更改所有副本的SelectionRules。
如何为每个副本设置此项?
以下是代码:
[Designer(typeof(BorderedTextBox_Designer))]
public partial class BorderedTextBox : UserControl
{
[Browsable(true), EditorBrowsable(EditorBrowsableState.Always)]
[Description("Controls whether the text of the edit control can span more than one line.")]
[Category("Behavior")]
[DefaultValue(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
public bool Multiline
{
set
{
//Set to TRUE:
if (value)
{
BorderedTextBox_Designer.SelectionRule = BorderedTextBox_Designer.SelectionRulesEnum.All;
}
//Set to FALSE:
else
{
BorderedTextBox_Designer.SelectionRule = BorderedTextBox_Designer.SelectionRulesEnum.RightLeft;
}
}
}
}
internal class BorderedTextBox_Designer : ControlDesigner
{
internal static SelectionRulesEnum SelectionRule;
public override SelectionRules SelectionRules
{
get
{
switch (SelectionRule)
{
case SelectionRulesEnum.All:
return SelectionRules.Visible | SelectionRules.Moveable | SelectionRules.AllSizeable;
case SelectionRulesEnum.UpDown:
return SelectionRules.Visible | SelectionRules.Moveable | SelectionRules.TopSizeable | SelectionRules.BottomSizeable;
case SelectionRulesEnum.RightLeft:
return SelectionRules.Visible | SelectionRules.Moveable | SelectionRules.LeftSizeable | SelectionRules.RightSizeable;
case SelectionRulesEnum.None:
return SelectionRules.Visible | SelectionRules.Moveable;
default:
return SelectionRules.Visible | SelectionRules.Moveable;
}
}
}
internal enum SelectionRulesEnum
{
All,
UpDown,
RightLeft,
None
}
}
答案 0 :(得分:1)
我已经弄清楚了。感谢Sinatr提示:)
答案是从用户控件将属性设置为ControlDesigner的实例。
而不是静态类=>在这种情况下,属性变化将是全局的,因为我的问题是。
这是一个代码示例:
var bardata = [];
d3.tsv('data.tsv', function(data){
for (key in data){
bardata.push(data[key].value)
}
var margin = {top:30, right:30, bottom:40, left:50}
var height = 400 - margin.top - margin.bottom,
width = 400 - margin.left - margin.right,
barWidth = 50,
barOffset = 5;
var tempColor;
var yScale = d3.scaleLinear()
.domain([0, d3.max(bardata)])
.range([0, height]);
var xScale = d3.scaleBand()
.domain(d3.range(0, bardata.length))
.padding(0.1)
.range([0, width]);
var tooltip = d3.select('body').append('div')
.style('position', 'absolute')
.style('padding', '0 10px')
.style('background', 'white')
.style('opacity', 0)
var myChart = d3.select('#chart').append('svg')
.style('background', '#E7E0CB')
.attr('width', width + margin.right + margin.left)
.attr('height', height + margin.top + margin.bottom)
.append('g')
.attr('transform', 'translate('+ margin.left +', '+ margin.top +')')
.style('background', '#C9D7D6')
.selectAll('rect').data(bardata)
.enter().append('rect')
.style('fill', '#C61C6F')
.attr('width', xScale.bandwidth())
.attr('x', function(d, i) {
return xScale(i);
})
.attr('height', 0)
.attr('y', height)
.on('mouseover', function(d){
d3.select(this)
.style('opacity', 0.5)
})
.on('mouseleave', function(d){
d3.select(this)
.style('opacity', 1)
})
.on('mouseover', function(d){
tooltip.transition()
.style('opacity', 0.9)
tooltip.html(d)
.style('left', (d3.event.pageX - 35) + 'px')
.style('top', (d3.event.pageY - 30) + 'px')
tempColor = this.style.fill;
d3.select(this)
.style('opacity', 0.5)
.style('fill', 'yellow')
})
.on('mouseleave', function(d){
tempColor = this.style.fill;
d3.select(this)
.style('opacity', 1)
.style('fill', '#C61C6F')
})
myChart.transition()
.attr('height', function(d){
return yScale(d);
})
.attr('y', function(d){
return height - yScale(d);
})
.delay(function(d, i){
return i * 20;
})
.duration(1000)
.ease(d3.easeElastic)
var vGuideScale = d3.scaleLinear()
.domain([0, d3.max(bardata)])
.range([0, height]);
var vAxis = d3.axisLeft(vGuideScale).ticks(10)
var vGuide = d3.select('svg').append('g')
vAxis(vGuide)
vGuide.attr('transform', 'translate('+ margin.left +', '+ margin.top +')')
var hAxis = d3.axisBottom(xScale).tickValues(xScale.domain().filter(function(d,i){
return !(i % (bardata.length/5))
}))
var hGuide = d3.select('svg').append('g')
hAxis(hGuide)
hGuide.attr('transform', 'translate('+ margin.left +', '+ (height + margin.top) +')')
});