- [DATABASE] Hướng dẫn thêm và cập nhật Extended Property Column trong Table Sqlserver
- [DEVEXPRESS] Hướng dẫn sử dụng Vertical Gridview để hiển thị thông tin sản phẩm
- [C#] Hướng dẫn sử dụng Json Schema để Validate chuỗi string có phải json
- [C#] Hướng dẫn sử dụng công cụ Clean Code trên Visual Studio
- [C#] Hướng dẫn Drag and Drop File vào RichTextBox
- [C#] Hướng dẫn tạo hiệu ứng Karaoke Text Effect Winform
- [C#] Sử dụng thư viện ZedGraph vẽ biểu đồ Line, Bar, Pie trên Winform
- [DATABASE] Hướng dẫn sort sắp xếp địa chỉ IP trên sqlserver sử dụng hàm PARSENAME
- [C#] Theo dõi sử kiện process Start hay Stop trên Winform
- [ASP.NET] Chia sẻ source code chụp hình sử dụng camera trên website
- [C#] Chạy ứng dụng trên Virtual Desktop (màn hình ảo) Winform
- [C#] Mã hóa và giải mã Data Protection API trên winform
- [C#] Hướng dẫn tạo Gradient Background trên Winform
- [DATABASE] Hướng dẫn convert Epoch to DateTime trong sqlserver
- [DATABASE] Hướng dẫn sử dụng STRING_AGG và CONCAT_WS trong sqlserver 2017
- [C#] Hướng dẫn Copy With All Property in Class Object
- [DEVEXPRESS] Hướng dẫn load Json DataSource vào GridView
- [C#] Hướng dẫn tạo chữ ký trên winform Signature Pad
- [DEVEXPRESS] Format code T-SQL highlight in RichEditControl
- [C#] Hướng dẫn upload file, hình ảnh từ Winform lên server API ASP.NET Core
[C#] Hướng dẫn đảo nội dung bài viết trong lập trình winform
Xin chào các bạn, bài viết hôm nay mình sẻ tiếp tục hướng dẫn các bạn các đảo nội dung bài viết trong lập trình C#, winform.
[C#] How to Rotate Text in csharp Winform
VD: mình có đoạn văn như sau
- Tin 1 : “mua ban sim so dep,cho thue sim so dep,lien he 0989 999 999“
- Tin 2: “cho thue sim so dep, mua ban sim so dep,lien he 0989 999 999“
- Tin 3: “lien he 0989 999 999,mua ban sim so dep, cho thue sim so dep“
- Tin 4 : “cho thue sim so dep,lien he 0989 999 999, mua ban sim so dep“
Ở đoạn trên, các bạn thấy các dữ liệu trong đoạn được đảo nhau bằng cách dấu phẩy (,)
Thuật toán ở đây chúng ta muốn đảo đơn giản là:
VD: abc => kết quả đảo
acb, bca, cab, abc, cba, bac.
Từ abc có 3 ký tự: số kết quả đảo được chính là 3! = 6 (3 giai thừa)
Giao diện demo ứng dụng đảo đoạn văn bản C#, winform:
Các bạn có thể ứng dụng này để làm content spin.
Class Algorithms.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SpinEditorApp.Helpers
{
class Algorithms
{
private int elementLevel = -1;
private int numberOfElements;
private int[] permutationValue = new int[0];
private char[] inputSet;
public char[] InputSet
{
get { return inputSet; }
set { inputSet = value; }
}
private int permutationCount = 0;
public int PermutationCount
{
get { return permutationCount; }
set { permutationCount = value; }
}
public char[] MakeCharArray(string InputString)
{
char[] charString = InputString.ToCharArray();
Array.Resize(ref permutationValue, charString.Length);
numberOfElements = charString.Length;
return charString;
}
public void Recursion(int k)
{
elementLevel++;
permutationValue.SetValue(elementLevel, k);
if (elementLevel == numberOfElements)
{
OutputPermutation(permutationValue);
}
else
{
for (int i = 0; i < numberOfElements; i++)
{
if (permutationValue[i] == 0)
{
Recursion(i);
}
}
}
elementLevel--;
permutationValue.SetValue(0, k);
}
public List<string> list = new List<string>();
private void OutputPermutation(int[] value)
{
var list_temp = new List<string>();
foreach (int i in value)
{
var _char = inputSet.GetValue(i - 1).ToString();
list_temp.Add(_char);
Console.Write(inputSet.GetValue(i - 1));
}
list.Add(string.Join(",", list_temp));
Console.WriteLine();
PermutationCount++;
}
}
}
Full source code Rotate Text c#:
using SpinEditorApp.Helpers;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace RotateSentence
{
public partial class Form1 : Form
{
public readonly char SYMBOL = ',';
public Form1()
{
InitializeComponent();
}
private async void btn_rotate_Click(object sender, EventArgs e)
{
var content = txt_input.Text.Trim();
var dataRotate = await RotateTextAsync(content);
lbl_result.Text = $"Kết quả đảo nội dung: {dataRotate.Count} kết quả đảo được.";
dataGridView1.DataSource = dataRotate;
}
public Task<List<Article>> RotateTextAsync(string content)
{
var task = Task.Run(() =>
{
var articles = new List<Article>();
var line = content.Split(SYMBOL);
var char_temp = "";
for (int i = 0; i < line.Length; i++)
{
char_temp += i;
}
Algorithms permAlgorithm = new Algorithms();
permAlgorithm.InputSet = permAlgorithm.MakeCharArray(char_temp);
permAlgorithm.Recursion(0);
var data = permAlgorithm.list;
foreach (var index in data)
{
List<string> list_data_temp = new List<string>();
var arr = index.Split(',');
foreach (var pos in arr)
{
var pos_int = Convert.ToInt32(pos);
list_data_temp.Add(line[pos_int]);
}
var rotateText = string.Join(",", list_data_temp);
var article = new Article();
article.id = articles.Count() + 1;
article.content = rotateText;
articles.Add(article);
}
return articles;
});
return task;
}
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
Process.Start("https://laptrinhvb.net");
}
}
public class Article
{
public int id { get; set; }
public string content { get; set; }
}
}
Thanks for watching!