**از زبان c#.net برای ساخت برنامه نوت پد استفاده کردم این برنامه شبیه به word هست تقریباً تمام امکانات قابل استفاده نوشته ام ،ولی مشکل اساسی این نیست.
مشکل من تیتر وپاراگراف هست که باید بطور خودکار بعد از اینتر زدن و رفتن به خط بعد خود برنامه نوع خط بالا که نوشته شده را تشخیص دهد که این کلمات نوشته شده عنوان است(بصورت توپر یا ضخیم عنوان را نمایش دهد) یا پاراگراف (اندازه فونت مثلا 13 و نوع فونت نازنین باشد) است ،هموطنان عزیزم میخوام به من کمک کنند!!!
یه دنیا ازشون ممنون میشم تا عمر دارم براشون دعا میکنم
**
[CSHARP]
private void Capitalize_Bold_FirstLine(object sender, EventArgs e)
{
RichTextBox box = sender as RichTextBox;
if (box != null && box.Text != "")
{
// get the current selection text of the textbox
int ss = box.SelectionStart;
int sl = box.SelectionLength;
// get the position where the first line ends
int firstLineEnd = box.Text.IndexOf('\n');
if (firstLineEnd < 0)
firstLineEnd = box.Text.Length;
// split the lines
string[] lines = box.Text.Split('\n');
// capitalize the first line
lines[0] = lines[0].ToUpper();
// join them back and set the new text
box.Text = String.Join("\n", lines);
// select the first line and make it bold
box.SelectionStart = 0;
box.SelectionLength = firstLineEnd;
box.SelectionFont = new Font(box.Font, FontStyle.Bold);
// select the rest and make it regular
box.SelectionStart = firstLineEnd;
box.SelectionLength = box.Text.Length - firstLineEnd;
box.SelectionFont = new Font(box.Font, FontStyle.Regular);
// go back to what the user had selected
box.SelectionStart = ss;
box.SelectionLength = sl;
}
}
private void richTextBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
richTextBox1.TextChanged += Capitalize_Bold_FirstLine;
}
}[/CSHARP]
MeeGo عزیز خیلی ممنون
میشه برنامه نوت پد با همین دستور بنویسی آپلود کنی؟؟؟؟؟؟
کد کامل:
[CSHARP]
using System;
using System.Drawing;
using System.Windows.Forms;
namespace RTBFL
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Capitalize_Bold_FirstLine(object sender, EventArgs e)
{
RichTextBox box = sender as RichTextBox;
if (box != null && box.Text != "")
{
// get the current selection text of the textbox
int ss = box.SelectionStart;
int sl = box.SelectionLength;
// get the position where the first line ends
int firstLineEnd = box.Text.IndexOf('\n');
if (firstLineEnd < 0)
firstLineEnd = box.Text.Length;
// split the lines
string[] lines = box.Text.Split('\n');
// capitalize the first line
lines[0] = lines[0].ToUpper();
// join them back and set the new text
box.Text = String.Join("\n", lines);
// select the first line and make it bold
box.SelectionStart = 0;
box.SelectionLength = firstLineEnd;
box.SelectionFont = new Font(box.Font, FontStyle.Bold);
// select the rest and make it regular
box.SelectionStart = firstLineEnd;
box.SelectionLength = box.Text.Length - firstLineEnd;
box.SelectionFont = new Font(box.Font, FontStyle.Regular);
// go back to what the user had selected
box.SelectionStart = ss;
box.SelectionLength = sl;
}
}
private void richTextBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
Capitalize_Bold_FirstLine(richTextBox1, e);
}
}
}
}
[/CSHARP]
کد بالا رو به برنامه اضافه کردم
ولی خط اول ما bold نمیشه و همنطور پارگراف ،مشکل از کجاست؟؟
سوال برنامه نویسی دارید؟
ندونستن عیب نیست، نپرسیدن چرا!