W
Wit
Hello,
I am writing a windows application using visual studio 2005 and embeded OWC
spreadsheet.
I am trying to display a control on top of a selected cell of
AxOWC11.AxSpreadsheet object.
My problem is the Range.Top, Rage.Left, Range.Width, and Range.Height
properties return values that are not quite right. I have to multiply these
values with 1.335 (made up value by try and error.)
However, the top and left returns the distant from the edge of the sheet;
these distants do not include the width and height of headings and toolbox.
I cannot get the combo box or any of my controls to sit perfectly on top of
the selected cell.
Here is segment of my code.
private void axSpreadsheet1_ClickEvent(object sender, EventArgs e)
{
this.label1.Text = ""; // ignor
this.comboBox1.Visible = false; // the combobox that should
display on top of selected cell
try
{
double rowHeaderWidth = 24;
double colHeaderHeight = 17;
double toolbarHeight = 22;
double magicNumber = 1.335;
int visibleCol =
this.axSpreadsheet1.ActiveWindow.VisibleRange.Column;
int visibleRow =
this.axSpreadsheet1.ActiveWindow.VisibleRange.Row;
OWC11.Range r = this.axSpreadsheet1.Selection;
this.label1.Text = s;
double left = variantToDouble(r.Left);
double top = variantToDouble(r.Top);
double width = variantToDouble(r.Width);
double height = variantToDouble(r.Height);
if (this.axSpreadsheet1.DisplayColumnHeadings == false)
colHeaderHeight = 0;
if (this.axSpreadsheet1.DisplayRowHeadings == false)
rowHeaderWidth = 0;
if (this.axSpreadsheet1.DisplayToolbar == false)
toolbarHeight = 0;
OWC11.Range reference =
(OWC11.Range)this.axSpreadsheet1.Cells[visibleRow, visibleCol]; // top left
of visibleRange
this.comboBox1.Left = (int)(((left -
variantToDouble(reference.Left)) * magicNumber) + rowHeaderWidth);
this.comboBox1.Top =
(int)((Math.Abs((variantToDouble(reference.Top) - top)) * magicNumber) +
colHeaderHeight + toolbarHeight);
this.comboBox1.Width = (int)(width * magicNumber);
this.comboBox1.Height = (int)(height * magicNumber);
int right = (int)(left + width);
int bottom = (int)(top + height);
}
catch (Exception ex)
{
this.label1.Text += " " + ex.ToString();
}
this.comboBox1.Visible = true;
}
private double variantToDouble(object o)
{
double d = 0;
double.TryParse(o.ToString(), out d);
return d;
}
Thank you,
Wit
I am writing a windows application using visual studio 2005 and embeded OWC
spreadsheet.
I am trying to display a control on top of a selected cell of
AxOWC11.AxSpreadsheet object.
My problem is the Range.Top, Rage.Left, Range.Width, and Range.Height
properties return values that are not quite right. I have to multiply these
values with 1.335 (made up value by try and error.)
However, the top and left returns the distant from the edge of the sheet;
these distants do not include the width and height of headings and toolbox.
I cannot get the combo box or any of my controls to sit perfectly on top of
the selected cell.
Here is segment of my code.
private void axSpreadsheet1_ClickEvent(object sender, EventArgs e)
{
this.label1.Text = ""; // ignor
this.comboBox1.Visible = false; // the combobox that should
display on top of selected cell
try
{
double rowHeaderWidth = 24;
double colHeaderHeight = 17;
double toolbarHeight = 22;
double magicNumber = 1.335;
int visibleCol =
this.axSpreadsheet1.ActiveWindow.VisibleRange.Column;
int visibleRow =
this.axSpreadsheet1.ActiveWindow.VisibleRange.Row;
OWC11.Range r = this.axSpreadsheet1.Selection;
this.label1.Text = s;
double left = variantToDouble(r.Left);
double top = variantToDouble(r.Top);
double width = variantToDouble(r.Width);
double height = variantToDouble(r.Height);
if (this.axSpreadsheet1.DisplayColumnHeadings == false)
colHeaderHeight = 0;
if (this.axSpreadsheet1.DisplayRowHeadings == false)
rowHeaderWidth = 0;
if (this.axSpreadsheet1.DisplayToolbar == false)
toolbarHeight = 0;
OWC11.Range reference =
(OWC11.Range)this.axSpreadsheet1.Cells[visibleRow, visibleCol]; // top left
of visibleRange
this.comboBox1.Left = (int)(((left -
variantToDouble(reference.Left)) * magicNumber) + rowHeaderWidth);
this.comboBox1.Top =
(int)((Math.Abs((variantToDouble(reference.Top) - top)) * magicNumber) +
colHeaderHeight + toolbarHeight);
this.comboBox1.Width = (int)(width * magicNumber);
this.comboBox1.Height = (int)(height * magicNumber);
int right = (int)(left + width);
int bottom = (int)(top + height);
}
catch (Exception ex)
{
this.label1.Text += " " + ex.ToString();
}
this.comboBox1.Visible = true;
}
private double variantToDouble(object o)
{
double d = 0;
double.TryParse(o.ToString(), out d);
return d;
}
Thank you,
Wit