-
Notifications
You must be signed in to change notification settings - Fork 0
/
SearchResultForm.cs
150 lines (124 loc) · 4.75 KB
/
SearchResultForm.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
using MediaHarbor.Classes;
using MetroFramework;
using MetroFramework.Forms;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static MediaHarbor.Form1;
namespace MediaHarbor
{
public partial class SearchResultForm : MetroForm
{
LanguageManager manager = new LanguageManager();
ThemeString themes = new ThemeString();
Form1 form1Instance = new Form1();
public SearchResultForm(List<YouTubeVideo> videos)
{
string selectedtheme = form1Instance.ThemeOption;
InitializeComponent();
ChangeLanguage();
this.Name = manager.youtubeSearch;
flowLayoutPanel1.FlowDirection = FlowDirection.TopDown;
flowLayoutPanel1.AutoScroll = true; // Kaydırma özelliğini etkinleştir
PopulateResults(videos);
SetTheme(selectedtheme);
}
public void SetTheme(string theme)
{
if (theme == manager.lightTheme)
{
// richTextBox1 için renk değişimi
this.Theme = MetroThemeStyle.Light;
metroStyleManager1.Theme = MetroFramework.MetroThemeStyle.Light;
metroStyleManager1.Style = MetroFramework.MetroColorStyle.Purple;
}
else if (theme == manager.darkTheme)
{
this.Theme = MetroThemeStyle.Dark;
metroStyleManager1.Theme = MetroFramework.MetroThemeStyle.Dark;
metroStyleManager1.Style = MetroFramework.MetroColorStyle.Purple;
}
}
private void ChangeLanguage()
{
manager.SetCommonTranslations();
}
private void PopulateResults(List<YouTubeVideo> videos)
{
foreach (var video in videos)
{
AddResult(video);
}
}
private void AddResult(YouTubeVideo video)
{
Form1 form1Instance = new Form1();
string selectedtheme = form1Instance.ThemeOption;
Panel resultPanel = new Panel();
resultPanel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
resultPanel.Margin = new Padding(5);
resultPanel.AutoSize = false;
resultPanel.Size = new Size(flowLayoutPanel1.ClientSize.Width - 10, 120);
PictureBox thumbnailBox = new PictureBox();
thumbnailBox.SizeMode = PictureBoxSizeMode.StretchImage;
thumbnailBox.Size = new Size(120, 90);
thumbnailBox.ImageLocation = GetThumbnailUrl(video.VideoId);
Label titleLabel = new Label();
titleLabel.Text = video.Title;
titleLabel.AutoSize = true;
Button copyUrlButton = new Button();
copyUrlButton.Text = manager.copyURL;
copyUrlButton.Tag = GetVideoUrl(video.VideoId);
copyUrlButton.Click += CopyUrlButton_Click;
copyUrlButton.Dock = DockStyle.Bottom;
resultPanel.Controls.Add(titleLabel);
resultPanel.Controls.Add(thumbnailBox);
resultPanel.Controls.Add(copyUrlButton);
flowLayoutPanel1.Controls.Add(resultPanel);
// FlowLayoutPanel'ın FlowDirection'ını ayarla
flowLayoutPanel1.FlowDirection = FlowDirection.TopDown;
if (selectedtheme == manager.lightTheme)
{
titleLabel.ForeColor = Color.Black;
copyUrlButton.ForeColor = Color.Black;
copyUrlButton.BackColor = Color.White;
}
else if (selectedtheme == manager.darkTheme)
{
titleLabel.ForeColor = Color.White;
copyUrlButton.ForeColor = Color.White;
copyUrlButton.BackColor = Color.Black;
}
}
private string GetThumbnailUrl(string videoId)
{
return $"https://img.youtube.com/vi/{videoId}/default.jpg";
}
private string GetVideoUrl(string videoId)
{
return $"https://www.youtube.com/watch?v={videoId}";
}
private void CopyUrlButton_Click(object sender, EventArgs e)
{
Button button = (Button)sender;
string videoUrl = (string)button.Tag;
// Clipboard'e video URL'sini kopyala
Clipboard.SetText(videoUrl);
}
private void SearchResultForm_Load(object sender, EventArgs e)
{
}
}
public class YouTubeVideo
{
public string VideoId { get; set; }
public string Title { get; set; }
}
}