回复 3楼774828727的帖子
这个用例就需要多写写代码自定义了。CellRange 并没有暴露背景色等属性,所以最小的操作单位是 Cell:
- private void Form1_Load(object sender, EventArgs e)
- {
- this.fpSpread1.CellClick += new FarPoint.Win.Spread.CellClickEventHandler(fpSpread1_CellClick);
- this.fpSpread1.SelectionChanged += new FarPoint.Win.Spread.SelectionChangedEventHandler(fpSpread1_SelectionChanged);
- this.propertyGrid1.SelectedObject = this.fpSpread1.Sheets[0].Cells[0, 0];
- this.propertyGrid1.PropertyValueChanged += new PropertyValueChangedEventHandler(propertyGrid1_PropertyValueChanged);
- }
- CellRange cr = new CellRange(0, 0, 1, 1);
- void propertyGrid1_PropertyValueChanged(object s, PropertyValueChangedEventArgs e)
- {
- if (e.ChangedItem.Label=="BackColor")
- {
- int rowCount = cr.RowCount;
- int colCount = cr.ColumnCount;
- for (int i = 0; i < rowCount; i++)
- {
- for (int j = 0; j < colCount; j++)
- {
- this.fpSpread1.ActiveSheet.Cells[cr.Row + i, cr.Column + j].BackColor = ((System.Drawing.Color)(e.ChangedItem.Value));
- }
- }
- }
- }
- void fpSpread1_SelectionChanged(object sender, FarPoint.Win.Spread.SelectionChangedEventArgs e)
- {
- cr =e.Range;
- }
- void fpSpread1_CellClick(object sender, FarPoint.Win.Spread.CellClickEventArgs e)
- {
- this.propertyGrid1.SelectedObject = this.fpSpread1.Sheets[0].Cells[e.Row, e.Column];
- }
复制代码
如果还有其他需求,就按照这个思路实现即可。 |