- Katılım
- 21 Aralık 2023
- Mesajlar
- 117
- Çözümler
- 2
- Beğeniler
- 45
Merhaba, C# ile bir Program yapmaya çalıştım. Çoğu fonksiyon güzel çalışıyor ama kalem, silgi fonksiyonları çalışmıyor. Kalem'e veya Silgi'ye tıklayınca işlevleri çalışmıyor hareket etmede kalıyor. Silgi içinde Yazının üstüne beyaz renkte yazı değil de direkt yazılan yazıları yok etme gibi olsun istiyorum. Umarım kendimi anlatabilmişimdir.
Kod:
using System;
using System.Drawing;
using System.Windows.Forms;
using PdfiumViewer;
namespace PdfViewerApp
{
public class MainForm : Form
{
private Button openFileButton;
private Button penButton;
private Button eraserButton;
private Button moveButton;
private Button prevPageButton;
private Button nextPageButton;
private Panel sidePanel;
private Label schoolLabel;
private PdfViewer pdfViewer;
private PictureBox canvas;
private Bitmap canvasBitmap;
private string mode = "none";
private bool isDrawing = false;
private Point previousPoint;
public MainForm()
{
// Pencere
this.Text = "PDF Viewer";
this.Size = new System.Drawing.Size(1920, 1080);
// Yan panel
sidePanel = new Panel
{
BackColor = System.Drawing.Color.LightGray,
Width = 150,
Height = this.ClientSize.Height,
Location = new System.Drawing.Point(this.ClientSize.Width - 150, 0)
};
this.Controls.Add(sidePanel);
// Uygulama ismi
schoolLabel = new Label
{
Text = "PDF Viewer",
TextAlign = ContentAlignment.TopCenter,
Font = new Font("Arial", 12, FontStyle.Bold),
Dock = DockStyle.Top,
Height = 50
};
sidePanel.Controls.Add(schoolLabel);
// Dosya Aç ve yan panel
openFileButton = new Button
{
Text = "Dosya Aç",
Width = 100,
Height = 50,
Location = new Point((sidePanel.Width - 100) / 2, schoolLabel.Height + 20)
};
openFileButton.Click += new EventHandler(OpenFileButton_Click);
sidePanel.Controls.Add(openFileButton);
// Kalem butonu
penButton = new Button
{
Text = "Kalem",
Width = 100,
Height = 50,
Location = new Point((sidePanel.Width - 100) / 2, schoolLabel.Height + 90)
};
penButton.Click += new EventHandler(PenButton_Click);
sidePanel.Controls.Add(penButton);
// Silgi butonu
eraserButton = new Button
{
Text = "Silgi",
Width = 100,
Height = 50,
Location = new Point((sidePanel.Width - 100) / 2, schoolLabel.Height + 160)
};
eraserButton.Click += new EventHandler(EraserButton_Click);
sidePanel.Controls.Add(eraserButton);
// Hareket Et butonu
moveButton = new Button
{
Text = "Hareket Et",
Width = 100,
Height = 50,
Location = new Point((sidePanel.Width - 100) / 2, schoolLabel.Height + 230)
};
moveButton.Click += new EventHandler(MoveButton_Click);
sidePanel.Controls.Add(moveButton);
// Önceki Sayfa butonu
prevPageButton = new Button
{
Text = "Önceki Sayfa",
Width = 100,
Height = 50,
Location = new Point((sidePanel.Width - 100) / 2, schoolLabel.Height + 300)
};
prevPageButton.Click += new EventHandler(PrevPageButton_Click);
sidePanel.Controls.Add(prevPageButton);
// Sonraki Sayfa butonu
nextPageButton = new Button
{
Text = "Sonraki Sayfa",
Width = 100,
Height = 50,
Location = new Point((sidePanel.Width - 100) / 2, schoolLabel.Height + 370)
};
nextPageButton.Click += new EventHandler(NextPageButton_Click);
sidePanel.Controls.Add(nextPageButton);
// PDF görüntüleyici oluştur ve ana pencereye ekle
pdfViewer = new PdfViewer
{
Location = new Point(0, 0),
Size = new Size(1920 - sidePanel.Width, 1080),
Visible = true
};
this.Controls.Add(pdfViewer);
// Kanvas oluştur ve ana pencereye ekle
canvas = new PictureBox
{
Location = new Point(0, 0),
Size = new Size(1920 - sidePanel.Width, 1080),
BorderStyle = BorderStyle.Fixed3D
};
this.Controls.Add(canvas);
canvasBitmap = new Bitmap(canvas.Width, canvas.Height);
canvas.Image = canvasBitmap;
canvas.MouseDown += new MouseEventHandler(Canvas_MouseDown);
canvas.MouseMove += new MouseEventHandler(Canvas_MouseMove);
canvas.MouseUp += new MouseEventHandler(Canvas_MouseUp);
}
private void OpenFileButton_Click(object sender, EventArgs e)
{
using (OpenFileDialog openFileDialog = new OpenFileDialog())
{
openFileDialog.Title = "Dosya Seç";
openFileDialog.Filter = "PDF Dosyaları|*.pdf";
openFileDialog.FilterIndex = 1;
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
string selectedFile = openFileDialog.FileName;
pdfViewer.Document = PdfDocument.Load(selectedFile);
}
}
}
private void PenButton_Click(object sender, EventArgs e)
{
mode = "pen";
}
private void EraserButton_Click(object sender, EventArgs e)
{
mode = "eraser";
}
private void MoveButton_Click(object sender, EventArgs e)
{
mode = "move";
}
private void PrevPageButton_Click(object sender, EventArgs e)
{
if (pdfViewer.Document != null && pdfViewer.Document.PageCount > 1 && pdfViewer.Renderer.Page > 1)
{
pdfViewer.Renderer.Page--;
}
}
private void NextPageButton_Click(object sender, EventArgs e)
{
if (pdfViewer.Document != null && pdfViewer.Document.PageCount > 1 && pdfViewer.Renderer.Page < pdfViewer.Document.PageCount)
{
pdfViewer.Renderer.Page++;
}
}
private void Canvas_MouseDown(object sender, MouseEventArgs e)
{
if (mode == "pen" || mode == "eraser")
{
isDrawing = true;
previousPoint = e.Location;
}
}
private void Canvas_MouseMove(object sender, MouseEventArgs e)
{
if (isDrawing)
{
using (Graphics g = Graphics.FromImage(canvasBitmap))
{
if (mode == "pen")
{
g.DrawLine(Pens.Black, previousPoint, e.Location);
}
else if (mode == "eraser")
{
// Beyaz renk kullanarak silme
g.DrawLine(new Pen(Color.White, 10), previousPoint, e.Location);
}
}
previousPoint = e.Location;
canvas.Invalidate();
}
}
private void Canvas_MouseUp(object sender, MouseEventArgs e)
{
isDrawing = false;
}
[STAThread]
public static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
}
}
}
Son düzenleyen: Moderatör: