我写了一个关于Combox 的代码
int[] i = { 5, 6, 7, 80 };
foreach (int ii in i)
{
toolastripcombox.Items.Add(i);
private void ChangeFontSize( int fontSize) //改变文字大小
{
if (fontSize <= 0)
throw new InvalidProgramException("字号参数错误,不能小于等于0.0"); RichTextBox tempRichTextBox = new RichTextBox(); int curRtbStart = textEditor.SelectionStart; int len = textEditor.SelectionLength;
int tempRtbStart = 0; Font font = textEditor.SelectionFont;
if (len <= 1 && null != font)
{
textEditor.SelectionFont = new Font(font.Name, fontSize, font.Style);
return;
}
tempRichTextBox.Rtf = textEditor.SelectedRtf;
for (int i = 0; i < len; i++)
{
tempRichTextBox.Select(tempRtbStart + i, 1);
tempRichTextBox.SelectionFont =
new Font(tempRichTextBox.SelectionFont.Name,
fontSize, tempRichTextBox.SelectionFont.Style);
}
tempRichTextBox.Select(tempRtbStart, len);
textEditor.SelectedRtf = tempRichTextBox.SelectedRtf;
textEditor.Select(curRtbStart, len);
textEditor.Focus();
}
private void toolastripcombox_SelectedIndexChanged(object sender, EventArgs e)
{
ChangeFontSize(Int32.Parse(toolastripcombox.SelectedItem.ToString())); }
出现错误,提示是输入的格式不正确。不知道哪里错了?
int[] i = { 5, 6, 7, 80 };
foreach (int ii in i)
{
toolastripcombox.Items.Add(i);
private void ChangeFontSize( int fontSize) //改变文字大小
{
if (fontSize <= 0)
throw new InvalidProgramException("字号参数错误,不能小于等于0.0"); RichTextBox tempRichTextBox = new RichTextBox(); int curRtbStart = textEditor.SelectionStart; int len = textEditor.SelectionLength;
int tempRtbStart = 0; Font font = textEditor.SelectionFont;
if (len <= 1 && null != font)
{
textEditor.SelectionFont = new Font(font.Name, fontSize, font.Style);
return;
}
tempRichTextBox.Rtf = textEditor.SelectedRtf;
for (int i = 0; i < len; i++)
{
tempRichTextBox.Select(tempRtbStart + i, 1);
tempRichTextBox.SelectionFont =
new Font(tempRichTextBox.SelectionFont.Name,
fontSize, tempRichTextBox.SelectionFont.Style);
}
tempRichTextBox.Select(tempRtbStart, len);
textEditor.SelectedRtf = tempRichTextBox.SelectedRtf;
textEditor.Select(curRtbStart, len);
textEditor.Focus();
}
private void toolastripcombox_SelectedIndexChanged(object sender, EventArgs e)
{
ChangeFontSize(Int32.Parse(toolastripcombox.SelectedItem.ToString())); }
出现错误,提示是输入的格式不正确。不知道哪里错了?
这句Int32.Parse(comboBox1.SelectedItem.ToString());就通不过编译
MessageBox.Show(toolastripcombox.SelectedItem.ToString());
这样显示的是数字?不可能吧
这个LZ你调试一哈看 值是多少
这样调试
string str=toolastripcombox.SelectedItem.ToString();
看看str值是多少
if(XX==null)
{
XX=0;//为空的时候来个默认值就不会报错了
}
foreach (int ii in i)
{
toolastripcombox.Items.Add(i);
应该为
for (int j = 0; j < i.Length; j++)
{
toolastripcombox.Items.Add(i[j]);
}
原因我不清楚。请高手指点一下。